From 435f81708fdbd7f08ba2c724fb581289f313bde5 Mon Sep 17 00:00:00 2001 From: Lu17301156525 <128358973+Lu17301156525@users.noreply.github.com> Date: Thu, 18 Jan 2024 19:58:35 -0800 Subject: [PATCH] add config (#262) * add config * update config --- mockServer/config/config.js | 16 ++++++++++++++++ mockServer/src/app.js | 7 +++---- 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 mockServer/config/config.js diff --git a/mockServer/config/config.js b/mockServer/config/config.js new file mode 100644 index 0000000..dcd70e9 --- /dev/null +++ b/mockServer/config/config.js @@ -0,0 +1,16 @@ +/** + * Copyright (c) 2023 - present TinyEngine Authors. + * Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd. + * + * Use of this source code is governed by an MIT-style license. + * + * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, + * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR + * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS. + * + */ + +module.exports = { + port: process.env.MOCK_PORT || 9090, + env: process.env.NODE_ENV || 'development' // Current mode +} diff --git a/mockServer/src/app.js b/mockServer/src/app.js index 3c3f6d2..26c5b34 100644 --- a/mockServer/src/app.js +++ b/mockServer/src/app.js @@ -14,13 +14,12 @@ import Koa2 from 'koa' import KoaBody from 'koa-body' import KoaStatic from 'koa-static2' import path from 'path' -import MainRoutes from './routes/main-routes' +import { env, port } from '../config/config' import ErrorRoutesCatch from './middleware/ErrorRoutesCatch' import ErrorRoutes from './routes/error-routes' +import MainRoutes from './routes/main-routes' const app = new Koa2() -const env = process.env.NODE_ENV || 'development' // Current mode -const PORT = 9090 app .use((ctx, next) => { ctx.set('Access-Control-Allow-Origin', '*') @@ -57,6 +56,6 @@ if (env === 'development') { }) } -app.listen(PORT) +app.listen(port) export default app