Add base URL to serve file system store objects over HTTP
This commit is contained in:
parent
13224f75ea
commit
fb3a497119
|
@ -15,7 +15,12 @@ ASSETS_HTTP_ROOT=
|
|||
# NOTE: Enabling the file system store will disable serving assets over HTTP.
|
||||
FILE_STORE=filesystem
|
||||
|
||||
# The base path for the file system store.
|
||||
|
||||
# The base URL used for serving file store assets.
|
||||
# Example: http://localhost:8888
|
||||
FILE_STORE_HTTP_BASE_URL=
|
||||
|
||||
# The root directory for the file system store.
|
||||
FILE_STORE_HTTP_ROOT=data/
|
||||
|
||||
# AWS credentials, required for the S3 store.
|
||||
|
|
|
@ -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.FileStoreHTTPRoot, "/")
|
||||
return filestore.NewFileSystemStore(c.FileStoreHTTPRoot, c.FileStoreHTTPBaseURL)
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ type Config struct {
|
|||
DatabaseURL string
|
||||
FileStore FileStore
|
||||
FileStoreHTTPRoot string
|
||||
FileStoreHTTPBaseURL string
|
||||
AWSAccessKeyID string
|
||||
AWSSecretAccessKey string
|
||||
AWSRegion string
|
||||
|
@ -76,6 +77,11 @@ func NewFromEnv() (Config, error) {
|
|||
return Config{}, fmt.Errorf("invalid FILE_STORE value: %s", fileStoreString)
|
||||
}
|
||||
|
||||
fileStoreHTTPBaseURL := os.Getenv("FILE_STORE_HTTP_BASE_URL")
|
||||
if fileStoreHTTPBaseURL == "" {
|
||||
fileStoreHTTPBaseURL = "/"
|
||||
}
|
||||
|
||||
var awsAccessKeyID, awsSecretAccessKey, awsRegion, s3Bucket, fileStoreHTTPRoot string
|
||||
if fileStore == S3Store {
|
||||
awsAccessKeyID = os.Getenv("AWS_ACCESS_KEY_ID")
|
||||
|
@ -118,5 +124,6 @@ func NewFromEnv() (Config, error) {
|
|||
S3Bucket: s3Bucket,
|
||||
AssetsHTTPRoot: assetsHTTPRoot,
|
||||
FileStoreHTTPRoot: fileStoreHTTPRoot,
|
||||
FileStoreHTTPBaseURL: fileStoreHTTPBaseURL,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -63,7 +63,8 @@ func (s *FileSystemStore) GetObjectWithRange(ctx context.Context, key string, st
|
|||
|
||||
// GetURL returns an HTTP URL for the provided file path.
|
||||
func (s *FileSystemStore) GetURL(ctx context.Context, key string) (string, error) {
|
||||
url := url.URL{}
|
||||
var url url.URL
|
||||
url.Scheme = s.baseURL.Scheme
|
||||
url.Host = s.baseURL.Host
|
||||
url.Path = fmt.Sprintf("%s%s", s.baseURL.Path, key)
|
||||
return url.String(), nil
|
||||
|
|
Loading…
Reference in New Issue