Skip to content

Commit abff552

Browse files
committed
partially through adding convict
1 parent fa2b5eb commit abff552

File tree

4 files changed

+109
-1
lines changed

4 files changed

+109
-1
lines changed

config.ts

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import convict from "convict";
2+
3+
convict.addFormat(require("convict-format-with-validator").ipaddress);
4+
5+
// Define a schema
6+
const config = convict({
7+
env: {
8+
doc: "The application environment.",
9+
format: ["production", "development", "test"],
10+
default: "development",
11+
env: "NODE_ENV",
12+
},
13+
ip: {
14+
doc: "The IP address to bind.",
15+
format: "ipaddress",
16+
default: "127.0.0.1",
17+
env: "AWS_ACCESS_KEY_ID",
18+
},
19+
awsSecretAccessKey: {
20+
doc: "The port to bind.",
21+
format: "port",
22+
default: 8080,
23+
env: "AWS_SECRET_ACCESS_KEY"
24+
},
25+
s3Server: {
26+
doc: "Hostname of the S3 server",
27+
format: String,
28+
default: "minio"
29+
},
30+
s3ServerPort: {
31+
doc: "port on which the s3 server is listening",
32+
format: "port",
33+
default: 9000,
34+
env: "S3_SERVER_PORT"
35+
},
36+
s3ServerProto: {
37+
doc: "The http protocol for the S3 server",
38+
format: String,
39+
default: "http",
40+
env: "S3_SERVER_PROTO"
41+
},
42+
s3Region: {
43+
doc: "The AWS region in which the bucket is located",
44+
format: String,
45+
default: "us-east-1",
46+
env: "S3_REGION"
47+
}
48+
db: {
49+
host: {
50+
doc: "Database host name/IP",
51+
format: "*",
52+
default: "server1.dev.test",
53+
},
54+
name: {
55+
doc: "Database name",
56+
format: String,
57+
default: "users",
58+
},
59+
},
60+
admins: {
61+
doc: "Users with write access, or null to grant full access without login.",
62+
format: Array,
63+
nullable: true,
64+
default: null,
65+
},
66+
});
67+
68+
69+
S3_BUCKET_NAME: BUCKET_NAME,
70+
AWS_ACCESS_KEY_ID: "AKIAIOSFODNN7EXAMPLE",
71+
AWS_SECRET_ACCESS_KEY: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
72+
S3_SERVER: "minio",
73+
S3_SERVER_PORT: "9000",
74+
S3_SERVER_PROTO: "http",
75+
S3_REGION: "us-east-1",
76+
DEBUG: "true",
77+
S3_STYLE: "virtual",
78+
ALLOW_DIRECTORY_LIST: "false",
79+
PROVIDE_INDEX_PAGE: "",
80+
APPEND_SLASH_FOR_POSSIBLE_DIRECTORY: "",
81+
STRIP_LEADING_DIRECTORY_PATH: "",
82+
PREFIX_LEADING_DIRECTORY_PATH: "",
83+
AWS_SIGS_VERSION: "4",
84+
STATIC_SITE_HOSTING: "",
85+
PROXY_CACHE_MAX_SIZE: "10g",
86+
PROXY_CACHE_INACTIVE: "60m",
87+
PROXY_CACHE_VALID_OK: "1h",
88+
PROXY_CACHE_VALID_NOTFOUND: "1m",
89+
PROXY_CACHE_VALID_FORBIDDEN: "30s",
90+
91+
// Load environment dependent configuration
92+
const env = config.get("env");
93+
config.loadFile("./config/" + env + ".json");
94+
95+
// Perform validation
96+
config.validate({ allowed: "strict" });
97+
98+
export default config;

config/test.json

Whitespace-only changes.

package-lock.json

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"devDependencies": {
33
"@jest/globals": "^29.7.0",
4+
"@types/convict": "^6.1.6",
45
"@types/supertest": "^6.0.2",
56
"better-docs": "^2.7.2",
67
"convict": "^6.2.4",

0 commit comments

Comments
 (0)