File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,6 +16,9 @@ MONGO_ACCOUNTS_DATABASE_URI=mongodb://localhost:27017/hawk
1616# MongoDB URL for connecting to events database
1717MONGO_EVENTS_DATABASE_URI = mongodb://localhost:27017/hawk_events
1818
19+ # MongoDB appName for per-worker load attribution (e.g. hawk-worker-limiter)
20+ MONGO_APP_NAME =
21+
1922# JWT secret key for projects tokens
2023JWT_SECRET = qwerty
2124
Original file line number Diff line number Diff line change @@ -20,6 +20,11 @@ export class DatabaseController {
2020 */
2121 private readonly connectionUri : string ;
2222
23+ /**
24+ * Sent to MongoDB on handshake; overrides any `appName` query param in the URI
25+ */
26+ private readonly appName ?: string ;
27+
2328 /**
2429 * GridFSBucket object
2530 * Used to store files in GridFS
@@ -30,12 +35,14 @@ export class DatabaseController {
3035 * Creates controller instance
3136 *
3237 * @param connectionUri - mongo URI for connection
38+ * @param appName - MongoDB appName, defaults to `process.env.MONGO_APP_NAME`
3339 */
34- constructor ( connectionUri : string ) {
40+ constructor ( connectionUri : string , appName ?: string ) {
3541 if ( ! connectionUri ) {
3642 throw new DatabaseConnectionError ( 'Connection URI is not specified. Check .env' ) ;
3743 }
3844 this . connectionUri = connectionUri ;
45+ this . appName = appName ?? process . env . MONGO_APP_NAME ;
3946 }
4047
4148 /**
@@ -53,6 +60,7 @@ export class DatabaseController {
5360 this . connection = await connect ( this . connectionUri , {
5461 useNewUrlParser : true ,
5562 useUnifiedTopology : true ,
63+ ...( this . appName ? { appName : this . appName } : { } ) ,
5664 } ) ;
5765 this . db = await this . connection . db ( ) ;
5866
You can’t perform that action at this time.
0 commit comments