Skip to content
Snippets Groups Projects
Forked from whats-this / cdn-origin
28 commits behind the upstream repository.

Whats-This CDN Origin

Simple but quick Golang webserver that serves requests to get files and redirects from a PostgreSQL and SeaweedFS backend.

Requirements

  • PostgreSQL server with objects table
  • SeaweedFS cluster with files in the objects table

Usage

$ go get -u github.com/whats-this/cdn-origin

# With configuration file
$ cp $GOPATH/src/github.com/whats-this/cdn-origin/cdn-origin.sample.toml /etc/cdn-origin/cdn-origin.toml
$ vim /etc/cdn-origin/cdn-origin.toml
$ cdn-origin

# With environment variables
$ set DATABASE_CONNECTION_URL="postgres://postgres@localhost/data?sslmode=disable"
$ set SEAWEED_MASTER_URL="http://localhost:9333"
$ ...
$ cdn-origin

# With flags
$ cdn-origin \
    --database-connection-url="postgres://postgres@localhost/data?sslmode=disable" \
    --seaweed-master-url="http://localhost:9333" \
    ...

# Flags take precedence over environment variables, which take precedence over config files

Information about configuration variables and their purpose can be found in cdn-origin.sample.toml. Configuration is handled by Viper.

Metrics

If metrics.enable is true, request metadata will be indexed in the provided Elaticsearch server in the following format:

{
  "country_code": keyword,
  "hostname":     keyword,
  "object_type":  keyword,
  "status_code":  short,
  "@timestamp":   date // generated from `@timestamp` pipeline
}

The index and @timestamp pipeline are created automatically if cdn-origin has permission. Alternatively, the mapping and pipeline can be created by other means using the .json files in metrics/.

TODO

  • Process chunked files stored in SeaweedFS, similar to how SeaweedFS cli handles it
  • Add TTL to volume cache
  • Write tests
  • Add thumbnail functionality (SeaweedFS supports this)

License

cdn-origin is licensed under the MIT license. A copy of the MIT license can be found in LICENSE.