Skip to content

Commit

Permalink
feat: Path for the database can be specified using ENV
Browse files Browse the repository at this point in the history
-- The path for the db.json now can be specified using the env CONFIG_DB_PATH and defaults to db.json
-- Added ENV on the Dockerfile specifying the default location for the db.json file to be inside the /root folder
  • Loading branch information
GCastilho committed Dec 11, 2021
1 parent e0cb780 commit 2bd6acc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ENV CONFIG_SETTINGS=/root/settings.json
ENV CONFIG_TOKEN_SETTINGS=/root/token_settings.json
ENV CONFIG_USER_SETTINGS=/root/user_settings.json
ENV CONFIG_WEBSOCKET_PATH=/root/websocket.json
ENV CONFIG_DB_PATH=/root/db.json

# Install dependencies
COPY ./package*.json ./
Expand Down
2 changes: 2 additions & 0 deletions src/common-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface ConfigPaths {
settings: ConfigPath
user_settings: ConfigPath
websocket_path: ConfigPath
db_path: ConfigPath
}

export function readConfigPathsFromENV(): ConfigPaths {
Expand All @@ -40,5 +41,6 @@ export function readConfigPathsFromENV(): ConfigPaths {
token_settings: process.env.CONFIG_TOKEN_SETTINGS || 'token_settings.json',
user_settings: process.env.CONFIG_USER_SETTINGS || 'user_settings.json',
websocket_path: process.env.CONFIG_WEBSOCKET_PATH || 'websocket.json',
db_path: process.env.CONFIG_DB_PATH || 'db.json',
}
}
2 changes: 1 addition & 1 deletion src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const configPaths: ConfigPaths = readConfigPathsFromENV()
const test_override_http = !process.env.OVERRIDE_USE_HTTP

// lowdb init
const order_db: OrderDB = lowdb(new FileSync<OrderSchema>('db.json'))
const order_db: OrderDB = lowdb(new FileSync<OrderSchema>(configPaths.db_path))
const tracking_db: UserDB = lowdb(new FileSync<UserSchema>(configPaths.websocket_path))
order_db.defaults({orders: []}).write()
tracking_db.defaults({users: []}).write()
Expand Down

0 comments on commit 2bd6acc

Please sign in to comment.