UNPKG

onions-node

Version:

onions-node backend

48 lines (46 loc) 1.33 kB
const initBackend = require('./init_backend') const path = require('path') module.exports = (configFilePath, rootPath) => { const getScriptType = () => { const script = process.argv[1] if (script.includes('build.js')) { return 'build' } if (script.includes('test.js')) { return 'test' } if (script.includes('start.js')) { return 'start' } if (script.includes('eject.js')) { return 'eject' } } const scriptType = getScriptType() if (scriptType !== 'start') { 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 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 } }