Skip to content

Commit 080605a

Browse files
Add configuration file (#573)
Add configuration file under the server/ directory
1 parent f1e1977 commit 080605a

File tree

2 files changed

+57
-22
lines changed

2 files changed

+57
-22
lines changed

server/config/config.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) 2024 Uber Technologies Inc.
2+
//
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
const {
23+
PEERS_DEFAULT,
24+
REQUEST_RETRY_FLAGS_DEFAULT,
25+
REQUEST_RETRY_LIMIT_DEFAULT,
26+
REQUEST_TIMEOUT_DEFAULT,
27+
SERVICE_NAME_DEFAULT,
28+
TRANSPORT_CLIENT_TYPE_DEFAULT,
29+
} = require('../constants');
30+
31+
module.exports = {
32+
peers: process.env.CADENCE_TCHANNEL_PEERS || PEERS_DEFAULT,
33+
transportClientType:
34+
process.env.TRANSPORT_CLIENT_TYPE || TRANSPORT_CLIENT_TYPE_DEFAULT,
35+
useWebpack: process.env.NODE_ENV !== 'production',
36+
enableAuth: process.env.ENABLE_AUTH === 'true',
37+
authType: process.env.AUTH_TYPE,
38+
authAdminJwtPrivateKey: process.env.AUTH_ADMIN_JWT_PRIVATE_KEY,
39+
requestConfig: {
40+
retryFlags: REQUEST_RETRY_FLAGS_DEFAULT,
41+
retryLimit:
42+
process.env.CADENCE_TCHANNEL_RETRY_LIMIT || REQUEST_RETRY_LIMIT_DEFAULT,
43+
serviceName: process.env.CADENCE_TCHANNEL_SERVICE || SERVICE_NAME_DEFAULT,
44+
timeout: REQUEST_TIMEOUT_DEFAULT,
45+
},
46+
};

server/index.js

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,11 @@ const koaStatic = require('koa-static');
2929
const koaWebpack = require('koa-webpack');
3030
const webpack = require('webpack');
3131
const jwt = require('jsonwebtoken');
32-
3332
const webpackConfig = require('../webpack.config');
3433
const grpcClient = require('./middleware/grpc-client');
3534
const tchannelClient = require('./middleware/tchannel-client');
3635
const router = require('./router');
37-
const {
38-
PEERS_DEFAULT,
39-
REQUEST_RETRY_FLAGS_DEFAULT,
40-
REQUEST_RETRY_LIMIT_DEFAULT,
41-
REQUEST_TIMEOUT_DEFAULT,
42-
SERVICE_NAME_DEFAULT,
43-
TRANSPORT_CLIENT_TYPE_DEFAULT,
44-
} = require('./constants');
45-
36+
const config = require('./config/config');
4637
const staticRoot = path.join(__dirname, '../dist');
4738
const app = new Koa();
4839
const transportClients = {
@@ -54,18 +45,16 @@ app.webpackConfig = webpackConfig;
5445

5546
app.init = function({
5647
logErrors,
57-
peers = process.env.CADENCE_TCHANNEL_PEERS || PEERS_DEFAULT,
58-
retryFlags = REQUEST_RETRY_FLAGS_DEFAULT,
59-
retryLimit = process.env.CADENCE_TCHANNEL_RETRY_LIMIT ||
60-
REQUEST_RETRY_LIMIT_DEFAULT,
61-
serviceName = process.env.CADENCE_TCHANNEL_SERVICE || SERVICE_NAME_DEFAULT,
62-
timeout = REQUEST_TIMEOUT_DEFAULT,
63-
transportClientType = process.env.TRANSPORT_CLIENT_TYPE ||
64-
TRANSPORT_CLIENT_TYPE_DEFAULT, // 'tchannel', 'grpc'
65-
useWebpack = process.env.NODE_ENV !== 'production',
66-
enableAuth = process.env.ENABLE_AUTH === 'true',
67-
authType = process.env.AUTH_TYPE,
68-
authAdminJwtPrivateKey = process.env.AUTH_ADMIN_JWT_PRIVATE_KEY,
48+
peers = config.peers,
49+
retryFlags = config.requestConfig.retryFlags,
50+
retryLimit = config.requestConfig.retryLimit,
51+
serviceName = config.requestConfig.serviceName,
52+
timeout = config.requestConfig.timeout,
53+
transportClientType = config.transportClientType,
54+
useWebpack = config.useWebpack,
55+
enableAuth = config.enableAuth,
56+
authType = config.authType,
57+
authAdminJwtPrivateKey = config.authAdminJwtPrivateKey,
6958
} = {}) {
7059
const requestConfig = {
7160
retryFlags,

0 commit comments

Comments
 (0)