diff --git a/index.js b/index.js index c4488f1b..a8686b31 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,6 @@ global.appRoot = __dirname const isDev = process.env.NODE_ENV !== 'production' if (isDev) { const devEnv = require('./dev').config - process.env.NODE_ENV = 'development' if (devEnv.Port) process.env.PORT = devEnv.Port if (devEnv.ConfigPath) process.env.CONFIG_PATH = devEnv.ConfigPath if (devEnv.MetadataPath) process.env.METADATA_PATH = devEnv.MetadataPath diff --git a/server/Logger.js b/server/Logger.js index 8283e1f0..6b589400 100644 --- a/server/Logger.js +++ b/server/Logger.js @@ -7,6 +7,7 @@ class Logger { this.logManager = null this.isDev = process.env.NODE_ENV !== 'production' + this.logLevel = !this.isDev ? LogLevel.INFO : LogLevel.TRACE this.socketListeners = [] } @@ -49,7 +50,7 @@ class Logger { } addSocketListener(socket, level) { - var index = this.socketListeners.findIndex(s => s.id === socket.id) + var index = this.socketListeners.findIndex((s) => s.id === socket.id) if (index >= 0) { this.socketListeners.splice(index, 1, { id: socket.id, @@ -66,7 +67,7 @@ class Logger { } removeSocketListener(socketId) { - this.socketListeners = this.socketListeners.filter(s => s.id !== socketId) + this.socketListeners = this.socketListeners.filter((s) => s.id !== socketId) } /** @@ -135,8 +136,8 @@ class Logger { /** * Fatal errors are ones that exit the process * Fatal logs are saved to crash_logs.txt - * - * @param {...any} args + * + * @param {...any} args */ fatal(...args) { console.error(`[${this.timestamp}] FATAL:`, ...args, `(${this.source})`) @@ -148,4 +149,4 @@ class Logger { this.handleLog(LogLevel.NOTE, args, this.source) } } -module.exports = new Logger() \ No newline at end of file +module.exports = new Logger() diff --git a/server/Server.js b/server/Server.js index 9de2f3f6..2d393a8d 100644 --- a/server/Server.js +++ b/server/Server.js @@ -50,6 +50,7 @@ class Server { global.MetadataPath = fileUtils.filePathToPOSIX(Path.normalize(METADATA_PATH)) global.RouterBasePath = ROUTER_BASE_PATH global.XAccel = process.env.USE_X_ACCEL + global.AllowCors = process.env.ALLOW_CORS === '1' if (!fs.pathExistsSync(global.ConfigPath)) { fs.mkdirSync(global.ConfigPath) @@ -182,11 +183,12 @@ class Server { * @see https://ionicframework.com/docs/troubleshooting/cors * * Running in development allows cors to allow testing the mobile apps in the browser + * or env variable ALLOW_CORS = '1' */ app.use((req, res, next) => { if (Logger.isDev || req.path.match(/\/api\/items\/([a-z0-9-]{36})\/(ebook|cover)(\/[0-9]+)?/)) { const allowedOrigins = ['capacitor://localhost', 'http://localhost'] - if (Logger.isDev || allowedOrigins.some((o) => o === req.get('origin'))) { + if (global.AllowCors || Logger.isDev || allowedOrigins.some((o) => o === req.get('origin'))) { res.header('Access-Control-Allow-Origin', req.get('origin')) res.header('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, DELETE, OPTIONS') res.header('Access-Control-Allow-Headers', '*')