diff --git a/config.ts b/config.ts new file mode 100644 index 00000000..f6fc749d --- /dev/null +++ b/config.ts @@ -0,0 +1,98 @@ +import convict from "convict"; + +convict.addFormat(require("convict-format-with-validator").ipaddress); + +// Define a schema +const config = convict({ + env: { + doc: "The application environment.", + format: ["production", "development", "test"], + default: "development", + env: "NODE_ENV", + }, + ip: { + doc: "The IP address to bind.", + format: "ipaddress", + default: "127.0.0.1", + env: "AWS_ACCESS_KEY_ID", + }, + awsSecretAccessKey: { + doc: "The port to bind.", + format: "port", + default: 8080, + env: "AWS_SECRET_ACCESS_KEY" + }, + s3Server: { + doc: "Hostname of the S3 server", + format: String, + default: "minio" + }, + s3ServerPort: { + doc: "port on which the s3 server is listening", + format: "port", + default: 9000, + env: "S3_SERVER_PORT" + }, + s3ServerProto: { + doc: "The http protocol for the S3 server", + format: String, + default: "http", + env: "S3_SERVER_PROTO" + }, + s3Region: { + doc: "The AWS region in which the bucket is located", + format: String, + default: "us-east-1", + env: "S3_REGION" + } + db: { + host: { + doc: "Database host name/IP", + format: "*", + default: "server1.dev.test", + }, + name: { + doc: "Database name", + format: String, + default: "users", + }, + }, + admins: { + doc: "Users with write access, or null to grant full access without login.", + format: Array, + nullable: true, + default: null, + }, +}); + + +S3_BUCKET_NAME: BUCKET_NAME, + AWS_ACCESS_KEY_ID: "AKIAIOSFODNN7EXAMPLE", + AWS_SECRET_ACCESS_KEY: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", + S3_SERVER: "minio", + S3_SERVER_PORT: "9000", + S3_SERVER_PROTO: "http", + S3_REGION: "us-east-1", + DEBUG: "true", + S3_STYLE: "virtual", + ALLOW_DIRECTORY_LIST: "false", + PROVIDE_INDEX_PAGE: "", + APPEND_SLASH_FOR_POSSIBLE_DIRECTORY: "", + STRIP_LEADING_DIRECTORY_PATH: "", + PREFIX_LEADING_DIRECTORY_PATH: "", + AWS_SIGS_VERSION: "4", + STATIC_SITE_HOSTING: "", + PROXY_CACHE_MAX_SIZE: "10g", + PROXY_CACHE_INACTIVE: "60m", + PROXY_CACHE_VALID_OK: "1h", + PROXY_CACHE_VALID_NOTFOUND: "1m", + PROXY_CACHE_VALID_FORBIDDEN: "30s", + +// Load environment dependent configuration +const env = config.get("env"); +config.loadFile("./config/" + env + ".json"); + +// Perform validation +config.validate({ allowed: "strict" }); + +export default config; diff --git a/config/test.json b/config/test.json new file mode 100644 index 00000000..e69de29b diff --git a/package-lock.json b/package-lock.json index cecc19e5..2dd2afde 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,9 +4,9 @@ "requires": true, "packages": { "": { - "name": "nginx-s3-gateway", "devDependencies": { "@jest/globals": "^29.7.0", + "@types/convict": "^6.1.6", "@types/supertest": "^6.0.2", "better-docs": "^2.7.2", "convict": "^6.2.4", @@ -1379,6 +1379,15 @@ "@types/babel-types": "*" } }, + "node_modules/@types/convict": { + "version": "6.1.6", + "resolved": "https://registry.npmjs.org/@types/convict/-/convict-6.1.6.tgz", + "integrity": "sha512-1B6jqWHWQud+7yyWAqbxnPmzlHrrOtJzZr1DhhYJ/NbpS4irfZSnq+N5Fm76J9LNRlUZvCmYxTVhhohWRvtqHw==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/cookiejar": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@types/cookiejar/-/cookiejar-2.1.5.tgz", diff --git a/package.json b/package.json index 724b57cf..73c187db 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "devDependencies": { "@jest/globals": "^29.7.0", + "@types/convict": "^6.1.6", "@types/supertest": "^6.0.2", "better-docs": "^2.7.2", "convict": "^6.2.4",