From c058c1c347582caa891d1bc57f2f66bc63677c94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=BE=E5=B3=B0=E7=9A=84=E5=A4=8F=E5=A4=A9?= Date: Tue, 16 Aug 2022 11:37:27 +0800 Subject: [PATCH] chore: enhance config (#88) --- config/config.default.js | 226 ++++++++++++++++++++------------------- config/config.prod.js | 8 ++ 2 files changed, 123 insertions(+), 111 deletions(-) diff --git a/config/config.default.js b/config/config.default.js index 9ff1933..059994a 100644 --- a/config/config.default.js +++ b/config/config.default.js @@ -3,115 +3,119 @@ const path = require('path'); const dbConfig = require('../database/config'); -const config = {}; - -config.siteFile = { - '/favicon.ico': 'https://macacajs.github.io/assets/favicon.ico', -}; - -// use for cookie sign key, should change to your own and keep security -config.keys = (process.env.RELIABLE_SECRET_KEY || 'reliable') + '_1528180445670_8068'; - -// add your config here -config.middleware = [ - 'forbidden', - 'hostRedirect', - 'openApiAuthorize', - 'authorize', - 'inject', - 'cors', - 'errorHandler', -]; - -config.hostRedirect = { - enable: !!process.env.RELIABLE_DEFAULT_HOST, - defaultHost: process.env.RELIABLE_DEFAULT_HOST, - ignore: [ - /^\/api\//, - ], -}; - -config.authorize = { - enable: process.env.RELIABLE_ENABLE_AUTHORIZE === 'Y', - ignore: [ - '/snsAuthorize/callback/dingtalk', - '/snsAuthorize/auth', - '/snsAuthorize/signout', - - '/api/gw', - '/api/latestBuild/:id', - '/api/app/:id', - '/api/build/:id', - ], - dingtalkAuth: { - appid: process.env.RELIABLE_AUTH_DINGTALK_APPID, - appsecret: process.env.RELIABLE_AUTH_DINGTALK_APPSECRET, - callbackUrl: '/snsAuthorize/callback/dingtalk', - }, -}; - -config.openApiAuthorize = { - enable: process.env.RELIABLE_ENABLE_OPENAPI_AUTHORIZE === 'Y', - match: [ - '/api/gw', - '/api/latestBuild/:id', - '/api/app/:id', - '/api/build/:id', - ], -}; - -config.session = { - maxAge: 48 * 3600 * 1000, // 48 hours - renew: true, // keep session -}; - -config.modelQueryConfig = { - pagination: { - // default num - num: 10, - }, -}; - -config.errorHandler = { - match: '/api', +// eslint-disable-next-line no-unused-vars +module.exports = appInfo => { + const config = exports = {}; + + config.siteFile = { + '/favicon.ico': 'https://macacajs.github.io/assets/favicon.ico', + }; + + // use for cookie sign key, should change to your own and keep security + config.keys = (process.env.RELIABLE_SECRET_KEY || 'reliable') + '_1528180445670_8068'; + + // add your config here + config.middleware = [ + 'forbidden', + 'hostRedirect', + 'openApiAuthorize', + 'authorize', + 'inject', + 'cors', + 'errorHandler', + ]; + + config.hostRedirect = { + enable: !!process.env.RELIABLE_DEFAULT_HOST, + defaultHost: process.env.RELIABLE_DEFAULT_HOST, + ignore: [ + /^\/api\//, + ], + }; + + config.authorize = { + enable: process.env.RELIABLE_ENABLE_AUTHORIZE === 'Y', + ignore: [ + '/snsAuthorize/callback/dingtalk', + '/snsAuthorize/auth', + '/snsAuthorize/signout', + + '/api/gw', + '/api/latestBuild/:id', + '/api/app/:id', + '/api/build/:id', + ], + dingtalkAuth: { + appid: process.env.RELIABLE_AUTH_DINGTALK_APPID, + appsecret: process.env.RELIABLE_AUTH_DINGTALK_APPSECRET, + callbackUrl: '/snsAuthorize/callback/dingtalk', + }, + }; + + config.openApiAuthorize = { + enable: process.env.RELIABLE_ENABLE_OPENAPI_AUTHORIZE === 'Y', + match: [ + '/api/gw', + '/api/latestBuild/:id', + '/api/app/:id', + '/api/build/:id', + ], + }; + + config.session = { + maxAge: 48 * 3600 * 1000, // 48 hours + renew: true, // keep session + }; + + config.modelQueryConfig = { + pagination: { + // default num + num: 10, + }, + }; + + config.errorHandler = { + match: '/api', + }; + + const reliableHost = process.env.RELIABLE_HOST || '127.0.0.1'; + + config.reliableView = { + serverUrl: '', + reliableHost, + }; + + config.security = { + csrf: { + enable: false, + }, + methodnoallow: { + enable: false, + }, + }; + + config.sequelize = dbConfig.development; + + const distDirName = 'dist'; + config.static = { + prefix: `/${distDirName}/`, + dir: path.resolve(__dirname, '..', 'view', distDirName), + }; + + config.site = { + logo: 'https://macacajs.github.io/reliable/logo/reliable.svg', + name: 'Reliable', + links: { + document: 'https://macacajs.github.io/reliable', + issues: 'https://github.com/macacajs/reliable/issues?utf8=%E2%9C%93&q=', + }, + }; + + config.admin = { + userKey: '', + list: [], + }; + + // inject-extra-config + return config; }; - -const reliableHost = process.env.RELIABLE_HOST || '127.0.0.1'; - -config.reliableView = { - serverUrl: '', - reliableHost, -}; - -config.security = { - csrf: { - enable: false, - }, - methodnoallow: { - enable: false, - }, -}; - -config.sequelize = dbConfig.development; - -const distDirName = 'dist'; -config.static = { - prefix: `/${distDirName}/`, - dir: path.resolve(__dirname, '..', 'view', distDirName), -}; - -config.site = { - logo: 'https://macacajs.github.io/reliable/logo/reliable.svg', - name: 'Reliable', - links: { - document: 'https://macacajs.github.io/reliable', - issues: 'https://github.com/macacajs/reliable/issues?utf8=%E2%9C%93&q=', - }, -}; - -config.admin = { - userKey: '', - list: [], -}; - -module.exports = config; diff --git a/config/config.prod.js b/config/config.prod.js index b4e0b87..7fa258e 100644 --- a/config/config.prod.js +++ b/config/config.prod.js @@ -2,3 +2,11 @@ const dbConfig = require('../database/config'); exports.sequelize = dbConfig.production; + +// eslint-disable-next-line no-unused-vars +module.exports = appInfo => { + const config = exports = {}; + + // inject-extra-config + return config; +};