UNPKG

onions-node

Version:

onions-node backend

32 lines (30 loc) 984 B
const initBackend = require('./init_backend') const path = require('path') module.exports = (configFilePath, rootPath) => { if (!configFilePath) { return (devServerConfig) => devServerConfig } let config try { if (!path.isAbsolute(configFilePath)) { configFilePath = path.join(rootPath, configFilePath) } config = require(configFilePath) } catch (e) { throw new Error('can not find config file, plz check your input!') } process.env.HOST = config.host || '0.0.0.0' process.env.PORT = config.port || 3000 return (devServerConfig) => { const before = devServerConfig.before || function beforeHandler() {} devServerConfig.before = (app, server) => { before(app, server) config.inDevServer = true initBackend(config, rootPath, app) } devServerConfig.port = config.port || 3000 devServerConfig.host = config.host || '0.0.0.0' devServerConfig.historyApiFallback = false return devServerConfig } }