Skip to content
This repository was archived by the owner on May 10, 2020. It is now read-only.

Commit 7e9ae4a

Browse files
committed
feat: add core/config for overriding PORT
1 parent 2cd42b7 commit 7e9ae4a

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

core/config.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const { PORT, NODE_ENV } = process.env
2+
3+
const APP_CONFIG = {
4+
shared: {
5+
6+
},
7+
8+
development: {
9+
PORT: parseInt(PORT, 10) || 3000
10+
},
11+
12+
production: {
13+
PORT: parseInt(PORT, 10) || 3010
14+
}
15+
}
16+
17+
// default to development config
18+
export default {
19+
...APP_CONFIG.shared,
20+
...(APP_CONFIG[NODE_ENV] || APP_CONFIG.development)
21+
}

run/utils/start-webpack-server.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ import Koa from 'koa'
44
import convert from 'koa-convert'
55
import webpack from 'webpack'
66

7+
import { PORT } from '../../core/config'
8+
79
export default () => {
810
const webpackServer = new Koa()
911
const compiler = webpack(require('../../webpack.config.babel'))
1012

1113
const config = {
12-
port: 3001,
14+
port: PORT + 1,
1315
options: {
14-
publicPath: 'http://localhost:3001/assets/',
16+
publicPath: `http://localhost:${PORT + 1}/assets/`,
1517
hot: true,
1618
stats: {
1719
assets: true,

server/koa.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import staticCache from 'koa-static-cache'
88

99
import createStore from 'app/store'
1010
import render from 'core/universal-render'
11+
import { PORT } from 'core/config'
1112

1213
const { NODE_ENV } = process.env
1314

@@ -16,7 +17,7 @@ const app = new Koa()
1617
// Proxy asset folder to webpack development server in development mode
1718
if (NODE_ENV === 'development') {
1819
const proxy = require('koa-proxy')({
19-
host: 'http://0.0.0.0:3001',
20+
host: `http://0.0.0.0:${PORT + 1}`,
2021
map: (filePath) => `assets/${filePath}`
2122
})
2223
app.use(convert(mount('/assets', proxy)))
@@ -52,8 +53,8 @@ app.use(async (ctx) => {
5253
}
5354
})
5455

55-
app.listen(3000)
56+
app.listen(PORT)
5657

5758
// Tell parent process koa-server is started
5859
if (process.send) process.send('online')
59-
debug('koa')('Application started on port 3000')
60+
debug('koa')('`koa-render-server` started on port %s', PORT)

webpack.config.babel.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import webpack from 'webpack'
44
import BrowserSyncPlugin from 'browser-sync-webpack-plugin'
55

66
import writeStats from './run/utils/write-stats'
7+
import { PORT } from './core/config'
78

89
import {
910
JS_REGEX,
@@ -22,7 +23,7 @@ export default {
2223
app: [
2324
'babel-polyfill',
2425
'react-hot-loader/patch',
25-
'webpack-hot-middleware/client?path=http://localhost:3001/__webpack_hmr',
26+
`webpack-hot-middleware/client?path=http://localhost:${PORT + 1}/__webpack_hmr`,
2627
resolve('./app')
2728
]
2829
},
@@ -49,8 +50,8 @@ export default {
4950
plugins: [
5051
new BrowserSyncPlugin({
5152
host: 'localhost',
52-
port: 3002,
53-
proxy: '0.0.0.0:3000'
53+
port: PORT + 2,
54+
proxy: `0.0.0.0:${PORT}`
5455
}, { reload: false }),
5556

5657
new webpack.HotModuleReplacementPlugin(),

0 commit comments

Comments
 (0)