mirror of
https://github.com/Terreii/andromeda-viewer.git
synced 2026-08-14 09:01:59 +00:00
chore(server): add a logger to the server
This commit is contained in:
+1
-1
@@ -25,7 +25,7 @@
|
||||
"update-files": "node tools/updateFiles.js",
|
||||
"test:docs": "textlint README.md ./*/*.md ./src/*/*.md",
|
||||
"test:standard": "standard",
|
||||
"test:server": "cross-env PORT=0 mocha",
|
||||
"test:server": "cross-env PORT=0 NODE_ENV=test mocha",
|
||||
"pretest:app": "npm run build:messages",
|
||||
"test:app": "react-scripts test --env=jsdom",
|
||||
"test": "npm-run-all -s test:standard test:docs test:server test:app",
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
const path = require('path')
|
||||
const express = require('express')
|
||||
const morgan = require('morgan')
|
||||
|
||||
const webSocketBridge = require('./bridge')
|
||||
const gridSession = require('./gridSession')
|
||||
|
||||
@@ -10,6 +12,15 @@ const app = express()
|
||||
const port = parseInt(process.env.PORT || 3001)
|
||||
const publicDir = process.env.NODE_ENV === 'production' ? 'build' : 'public'
|
||||
|
||||
// Add logger
|
||||
if (process.env.NODE_ENV !== 'test') { // but only if it is not a test
|
||||
const format = process.env.NODE_ENV === 'production'
|
||||
// like "common" but with an ISO-Date
|
||||
? ':remote-addr - :remote-user [:date[iso]] ":method :url HTTP/:http-version" :status :res[content-length]'
|
||||
: 'dev'
|
||||
app.use(morgan(format))
|
||||
}
|
||||
|
||||
gridSession(app)
|
||||
|
||||
app.use(express.static(publicDir))
|
||||
|
||||
+8
-5
@@ -1,25 +1,28 @@
|
||||
'use strict'
|
||||
|
||||
const { createProxyMiddleware } = require('http-proxy-middleware')
|
||||
|
||||
module.exports = process.env.SERVER === 'debug'
|
||||
? proxySetup
|
||||
: serverAndProxySetup
|
||||
|
||||
const { createProxyMiddleware } = require('http-proxy-middleware')
|
||||
const morgan = require('morgan')
|
||||
|
||||
/**
|
||||
* Setup a server and proxy.
|
||||
* @param {import('express').Application} app Express App.
|
||||
*/
|
||||
function serverAndProxySetup (app) {
|
||||
const logger = morgan('dev')
|
||||
|
||||
const webSocketBridge = require('../server/bridge')
|
||||
app.use(webSocketBridge.createWebSocketCreationRoute('/api/bridge'))
|
||||
|
||||
const gridSession = require('../server/gridSession')
|
||||
gridSession(app)
|
||||
|
||||
app.use('/api/account', require('../server/account'))
|
||||
app.post('/api/login', require('../server/login'))
|
||||
app.use('/api/proxy', require('../server/httpProxy'))
|
||||
app.use('/api/account', logger, require('../server/account'))
|
||||
app.post('/api/login', logger, require('../server/login'))
|
||||
app.use('/api/proxy', logger, require('../server/httpProxy'))
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user