Rename HTTP base path to HTTP root

This commit is contained in:
Rob Watson 2021-12-09 03:38:38 +01:00
parent 4168cb150c
commit 13224f75ea
5 changed files with 38 additions and 38 deletions

View File

@ -30,6 +30,6 @@ COPY --from=go-builder /app/clipper /bin/clipper
COPY --from=go-builder /root/go/bin/migrate /bin/migrate
COPY --from=node-builder /app/build /app/assets
ENV ASSETS_HTTP_BASE_PATH "/app/assets"
ENV ASSETS_HTTP_ROOT "/app/assets"
ENTRYPOINT ["/bin/clipper"]

View File

@ -7,7 +7,7 @@ DATABASE_URL=
# Optional. If set, files in this location will be served over HTTP at /.
# Mostly useful for deployment.
ASSETS_HTTP_BASE_PATH=
ASSETS_HTTP_ROOT=
# Set the store type - either s3 or filesystem. Defaults to filesystem. The S3
# store is recommended for production usage.
@ -16,7 +16,7 @@ ASSETS_HTTP_BASE_PATH=
FILE_STORE=filesystem
# The base path for the file system store.
FILE_STORE_HTTP_BASE_PATH=data/
FILE_STORE_HTTP_ROOT=data/
# AWS credentials, required for the S3 store.
AWS_ACCESS_KEY_ID=

View File

@ -101,5 +101,5 @@ func buildFileStore(ctx context.Context, c config.Config, logger *zap.Logger) (m
}
logger.Info("Initializing file sysytem store")
return filestore.NewFileSystemStore(c.FileStoreHTTPBasePath, "/")
return filestore.NewFileSystemStore(c.FileStoreHTTPRoot, "/")
}

View File

@ -21,18 +21,18 @@ const (
)
type Config struct {
Environment Environment
BindAddr string
TLSCertFile string
TLSKeyFile string
DatabaseURL string
FileStore FileStore
FileStoreHTTPBasePath string
AWSAccessKeyID string
AWSSecretAccessKey string
AWSRegion string
S3Bucket string
AssetsHTTPBasePath string
Environment Environment
BindAddr string
TLSCertFile string
TLSKeyFile string
DatabaseURL string
FileStore FileStore
FileStoreHTTPRoot string
AWSAccessKeyID string
AWSSecretAccessKey string
AWSRegion string
S3Bucket string
AssetsHTTPRoot string
}
func NewFromEnv() (Config, error) {
@ -76,7 +76,7 @@ func NewFromEnv() (Config, error) {
return Config{}, fmt.Errorf("invalid FILE_STORE value: %s", fileStoreString)
}
var awsAccessKeyID, awsSecretAccessKey, awsRegion, s3Bucket, fileStoreHTTPBasePath string
var awsAccessKeyID, awsSecretAccessKey, awsRegion, s3Bucket, fileStoreHTTPRoot string
if fileStore == S3Store {
awsAccessKeyID = os.Getenv("AWS_ACCESS_KEY_ID")
if awsAccessKeyID == "" {
@ -98,25 +98,25 @@ func NewFromEnv() (Config, error) {
return Config{}, errors.New("S3_BUCKET not set")
}
} else {
if fileStoreHTTPBasePath = os.Getenv("FILE_STORE_HTTP_BASE_PATH"); fileStoreHTTPBasePath == "" {
return Config{}, errors.New("FILE_STORE_HTTP_BASE_PATH not set")
if fileStoreHTTPRoot = os.Getenv("FILE_STORE_HTTP_ROOT"); fileStoreHTTPRoot == "" {
return Config{}, errors.New("FILE_STORE_HTTP_ROOT not set")
}
}
assetsHTTPBasePath := os.Getenv("ASSETS_HTTP_BASE_PATH")
assetsHTTPRoot := os.Getenv("ASSETS_HTTP_ROOT")
return Config{
Environment: env,
BindAddr: bindAddr,
TLSCertFile: tlsCertFile,
TLSKeyFile: tlsKeyFile,
DatabaseURL: databaseURL,
FileStore: fileStore,
AWSAccessKeyID: awsAccessKeyID,
AWSSecretAccessKey: awsSecretAccessKey,
AWSRegion: awsRegion,
S3Bucket: s3Bucket,
AssetsHTTPBasePath: assetsHTTPBasePath,
FileStoreHTTPBasePath: fileStoreHTTPBasePath,
Environment: env,
BindAddr: bindAddr,
TLSCertFile: tlsCertFile,
TLSKeyFile: tlsKeyFile,
DatabaseURL: databaseURL,
FileStore: fileStore,
AWSAccessKeyID: awsAccessKeyID,
AWSSecretAccessKey: awsSecretAccessKey,
AWSRegion: awsRegion,
S3Bucket: s3Bucket,
AssetsHTTPRoot: assetsHTTPRoot,
FileStoreHTTPRoot: fileStoreHTTPRoot,
}, nil
}

View File

@ -251,13 +251,13 @@ func Start(options Options) error {
// Enabling the file system store disables serving assets over HTTP.
// TODO: fix this.
if options.Config.AssetsHTTPBasePath != "" {
log.With("basePath", options.Config.AssetsHTTPBasePath).Info("Configured to serve assets over HTTP")
fileHandler = http.FileServer(http.Dir(options.Config.AssetsHTTPBasePath))
if options.Config.AssetsHTTPRoot != "" {
log.With("root", options.Config.AssetsHTTPRoot).Info("Configured to serve assets over HTTP")
fileHandler = http.FileServer(http.Dir(options.Config.AssetsHTTPRoot))
}
if options.Config.FileStoreHTTPBasePath != "" {
log.With("basePath", options.Config.FileStoreHTTPBasePath).Info("Configured to serve file store over HTTP")
fileHandler = http.FileServer(http.Dir(options.Config.FileStoreHTTPBasePath))
if options.Config.FileStoreHTTPRoot != "" {
log.With("root", options.Config.FileStoreHTTPRoot).Info("Configured to serve file store over HTTP")
fileHandler = http.FileServer(http.Dir(options.Config.FileStoreHTTPRoot))
}
httpServer := http.Server{