Skip to content

Commit 23eca79

Browse files
committed
fixed webpack dev server issue
1 parent ac41ab9 commit 23eca79

File tree

4 files changed

+24
-28
lines changed

4 files changed

+24
-28
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpack-typescript-react",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"description": "",
55
"license": "ISC",
66
"author": "",

webpack/constants/devproxy.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ export const pathRewrite = (localUrl, remoteUrl) => (path) =>
1010

1111
export const httpProxyTarget = {
1212
port: 80,
13-
protocol: 'http:',
13+
protocol: 'http',
1414
};
1515
export const httpsProxyTarget = {
1616
port: 443,
17-
protocol: 'https:',
17+
protocol: 'https',
1818
};
1919

20+
export const devServerHost = isWindows() ? '127.0.0.1' : '0.0.0.0';
21+
2022
export const devServerUrl = isWindows()
21-
? `http://127.0.0.1:${defaultPort}/`
22-
: `http://0.0.0.0:${defaultPort}/`;
23+
? `http://${devServerHost}:${defaultPort}/`
24+
: `http://${devServerHost}:${defaultPort}/`;

webpack/dev.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
import path from 'path';
2-
3-
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
41
/**
52
* Created by: Andrey Polyakov ([email protected])
63
*/
4+
import path from 'path';
5+
6+
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
77
import HtmlWebpackPlugin from 'html-webpack-plugin';
88

9-
import {defaultPort as port} from './constants/devproxy';
9+
import {devServerHost, defaultPort as port} from './constants/devproxy';
1010
import devProxyConfig from './resources/devProxy';
1111

1212
export default {
1313
devtool: '#cheap-module-source-map',
14-
stats: false,
1514
plugins: [
1615
new HtmlWebpackPlugin({
1716
filename: 'index.html',
@@ -28,5 +27,6 @@ export default {
2827
proxy: devProxyConfig,
2928
hot: true,
3029
overlay: false,
30+
host: devServerHost,
3131
},
3232
};

webpack/resources/devProxy.js

+12-18
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,16 @@
44
import {httpsProxyTarget, pathRewrite} from '../constants/devproxy';
55

66
export default {
7-
// '/world-time': {
8-
// target: {
9-
// host: 'worldtimeapi.org',
10-
// ...httpsProxyTarget
11-
// },
12-
// pathRewrite: pathRewrite('^/world-time/test', '/api'),
13-
// changeOrigin: true,
14-
// secure: false,
15-
// },
16-
// '/someurl/test': {
17-
// target: {
18-
// host: 'reqres.in',
19-
// ...httpsProxyTarget
20-
// },
21-
// pathRewrite: pathRewrite('^/someurl/test', '/api'),
22-
// changeOrigin: true,
23-
// secure: false,
24-
// }
7+
'/world-time': {
8+
target: `${httpsProxyTarget.protocol}://worldtimeapi.org:${httpsProxyTarget.port}`,
9+
pathRewrite: pathRewrite('^/world-time/test', '/api'),
10+
changeOrigin: true,
11+
secure: false,
12+
},
13+
'/someurl/test': {
14+
target: `${httpsProxyTarget.protocol}://reqres.in:${httpsProxyTarget.port}`,
15+
pathRewrite: pathRewrite('^/someurl/test', '/api'),
16+
changeOrigin: true,
17+
secure: false,
18+
},
2519
};

0 commit comments

Comments
 (0)