Restructure src, add modular design

This commit is contained in:
Yarmo Mackenbach 2022-11-14 21:39:26 +01:00
parent 34f34c3d6f
commit 79a259f028
No known key found for this signature in database
GPG key ID: 37367F4AF4087AD1
16 changed files with 22 additions and 16 deletions

View file

@ -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"

View file

@ -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

View file

@ -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