From 79a259f028626bc14254ea669fc3e812f2a7bc2f Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Mon, 14 Nov 2022 21:39:26 +0100 Subject: [PATCH] Restructure src, add modular design --- package.json | 4 ++-- {api => src/api}/v0/index.js | 0 {api => src/api}/v1/index.js | 0 {api => src/api}/v2/index.js | 8 ++++++-- {api => src/api}/v2/keyoxide_profile.js | 0 {api => src/api}/v2/proxy_get.js | 0 src/index.js | 26 +++++++++++++------------ {routes => src/routes}/api.js | 0 {routes => src/routes}/main.js | 0 {routes => src/routes}/profile.js | 0 {routes => src/routes}/static.js | 0 {routes => src/routes}/util.js | 0 {server => src/server}/demo.js | 0 {server => src/server}/index.js | 0 {server => src/server}/keys.js | 0 {server => src/server}/utils.js | 0 16 files changed, 22 insertions(+), 16 deletions(-) rename {api => src/api}/v0/index.js (100%) rename {api => src/api}/v1/index.js (100%) rename {api => src/api}/v2/index.js (89%) rename {api => src/api}/v2/keyoxide_profile.js (100%) rename {api => src/api}/v2/proxy_get.js (100%) rename {routes => src/routes}/api.js (100%) rename {routes => src/routes}/main.js (100%) rename {routes => src/routes}/profile.js (100%) rename {routes => src/routes}/static.js (100%) rename {routes => src/routes}/util.js (100%) rename {server => src/server}/demo.js (100%) rename {server => src/server}/index.js (100%) rename {server => src/server}/keys.js (100%) rename {server => src/server}/utils.js (100%) diff --git a/package.json b/package.json index cb980f6..d65ebc3 100644 --- a/package.json +++ b/package.json @@ -49,8 +49,8 @@ "build:server": "ncc build ./src/index.js -e jsdom -o dist", "build:static": "webpack --config webpack.config.js --env static=true --env mode=production", "build:static:dev": "webpack --config webpack.config.js --env static=true --env mode=development", - "standard:check": "./node_modules/.bin/standard ./src ./api ./routes ./server", - "standard:fix": "./node_modules/.bin/standard --fix ./src ./api ./routes ./server", + "standard:check": "./node_modules/.bin/standard ./src", + "standard:fix": "./node_modules/.bin/standard --fix ./src", "license:check": "./node_modules/.bin/license-check-and-add check", "license:add": "./node_modules/.bin/license-check-and-add add", "license:remove": "./node_modules/.bin/license-check-and-add remove" diff --git a/api/v0/index.js b/src/api/v0/index.js similarity index 100% rename from api/v0/index.js rename to src/api/v0/index.js diff --git a/api/v1/index.js b/src/api/v1/index.js similarity index 100% rename from api/v1/index.js rename to src/api/v1/index.js diff --git a/api/v2/index.js b/src/api/v2/index.js similarity index 89% rename from api/v2/index.js rename to src/api/v2/index.js index 3a22084..9be5548 100644 --- a/api/v2/index.js +++ b/src/api/v2/index.js @@ -33,7 +33,11 @@ import proxyGetApiRouter from './proxy_get.js' const router = express.Router() -router.use('/profile', keyoxideProfileApiRouter) -router.use('/get', proxyGetApiRouter) +if (process.env.ENABLE_MAIN_MODULE ?? true) { + router.use('/profile', keyoxideProfileApiRouter) +} +if (process.env.ENABLE_PROXY_MODULE ?? true) { + router.use('/get', proxyGetApiRouter) +} export default router diff --git a/api/v2/keyoxide_profile.js b/src/api/v2/keyoxide_profile.js similarity index 100% rename from api/v2/keyoxide_profile.js rename to src/api/v2/keyoxide_profile.js diff --git a/api/v2/proxy_get.js b/src/api/v2/proxy_get.js similarity index 100% rename from api/v2/proxy_get.js rename to src/api/v2/proxy_get.js diff --git a/src/index.js b/src/index.js index 9e15e29..ddd251a 100644 --- a/src/index.js +++ b/src/index.js @@ -34,11 +34,11 @@ import { stringReplace } from 'string-replace-middleware' import * as pug from 'pug' import 'dotenv/config.js' -import apiRoute from '../routes/api.js' -import mainRoute from '../routes/main.js' -import profileRoute from '../routes/profile.js' -import staticRoute from '../routes/static.js' -import utilRoute from '../routes/util.js' +import apiRoute from './routes/api.js' +import mainRoute from './routes/main.js' +import profileRoute from './routes/profile.js' +import staticRoute from './routes/static.js' +import utilRoute from './routes/util.js' const app = express() const packageData = JSON.parse(readFileSync('./package.json')) @@ -72,17 +72,19 @@ app.use(stringReplace({ })) // Routes -app.use('/favicon.svg', express.static('./static/favicon.svg')) -app.use('/robots.txt', express.static('./static/robots.txt')) +if (process.env.ENABLE_MAIN_MODULE ?? true) { + app.use('/favicon.svg', express.static('./static/favicon.svg')) + app.use('/robots.txt', express.static('./static/robots.txt')) -app.use('/', mainRoute) + app.use('/', mainRoute) + app.use('/static', staticRoute) + app.use('/util', utilRoute) + app.use('/', profileRoute) +} app.use('/api', apiRoute) -app.use('/static', staticRoute) -app.use('/util', utilRoute) -app.use('/', profileRoute) app.listen(app.get('port'), () => { - console.log(`Node server listening at http://localhost:${app.get('port')}`) + console.log(`Server listening at http://localhost:${app.get('port')}`) }) export default app diff --git a/routes/api.js b/src/routes/api.js similarity index 100% rename from routes/api.js rename to src/routes/api.js diff --git a/routes/main.js b/src/routes/main.js similarity index 100% rename from routes/main.js rename to src/routes/main.js diff --git a/routes/profile.js b/src/routes/profile.js similarity index 100% rename from routes/profile.js rename to src/routes/profile.js diff --git a/routes/static.js b/src/routes/static.js similarity index 100% rename from routes/static.js rename to src/routes/static.js diff --git a/routes/util.js b/src/routes/util.js similarity index 100% rename from routes/util.js rename to src/routes/util.js diff --git a/server/demo.js b/src/server/demo.js similarity index 100% rename from server/demo.js rename to src/server/demo.js diff --git a/server/index.js b/src/server/index.js similarity index 100% rename from server/index.js rename to src/server/index.js diff --git a/server/keys.js b/src/server/keys.js similarity index 100% rename from server/keys.js rename to src/server/keys.js diff --git a/server/utils.js b/src/server/utils.js similarity index 100% rename from server/utils.js rename to src/server/utils.js