jeduardogruiz
commited on
Commit
•
3c60bc3
1
Parent(s):
9b9e880
Create config/webpackDevServer.config.js
Browse files
config/webpackDevServer.config.js
ADDED
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"use strict";
|
2 |
+
|
3 |
+
const fs = require("fs");
|
4 |
+
const evalSourceMapMiddleware = require("react-dev-utils/evalSourceMapMiddleware");
|
5 |
+
const noopServiceWorkerMiddleware = require("react-dev-utils/noopServiceWorkerMiddleware");
|
6 |
+
const ignoredFiles = require("react-dev-utils/ignoredFiles");
|
7 |
+
const redirectServedPath = require("react-dev-utils/redirectServedPathMiddleware");
|
8 |
+
const paths = require("./paths");
|
9 |
+
const getHttpsConfig = require("./getHttpsConfig");
|
10 |
+
|
11 |
+
const host = process.env.HOST || "0.0.0.0";
|
12 |
+
const sockHost = process.env.WDS_SOCKET_HOST;
|
13 |
+
const sockPath = process.env.WDS_SOCKET_PATH; // default: '/ws'
|
14 |
+
const sockPort = process.env.WDS_SOCKET_PORT;
|
15 |
+
|
16 |
+
module.exports = function (proxy, allowedHost) {
|
17 |
+
const disableFirewall =
|
18 |
+
!proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === "true";
|
19 |
+
return {
|
20 |
+
// WebpackDevServer 2.4.3 introduced a security fix that prevents remote
|
21 |
+
// websites from potentially accessing local content through DNS rebinding:
|
22 |
+
// https://github.com/webpack/webpack-dev-server/issues/887
|
23 |
+
// https://medium.com/webpack/webpack-dev-server-middleware-security-issues-1489d950874a
|
24 |
+
// However, it made several existing use cases such as development in cloud
|
25 |
+
// environment or subdomains in development significantly more complicated:
|
26 |
+
// https://github.com/facebook/create-react-app/issues/2271
|
27 |
+
// https://github.com/facebook/create-react-app/issues/2233
|
28 |
+
// While we're investigating better solutions, for now we will take a
|
29 |
+
// compromise. Since our WDS configuration only serves files in the `public`
|
30 |
+
// folder we won't consider accessing them a vulnerability. However, if you
|
31 |
+
// use the `proxy` feature, it gets more dangerous because it can expose
|
32 |
+
// remote code execution vulnerabilities in backends like Django and Rails.
|
33 |
+
// So we will disable the host check normally, but enable it if you have
|
34 |
+
// specified the `proxy` setting. Finally, we let you override it if you
|
35 |
+
// really know what you're doing with a special environment variable.
|
36 |
+
// Note: ["localhost", ".localhost"] will support subdomains - but we might
|
37 |
+
// want to allow setting the allowedHosts manually for more complex setups
|
38 |
+
allowedHosts: disableFirewall ? "all" : [allowedHost],
|
39 |
+
headers: {
|
40 |
+
"Access-Control-Allow-Origin": "*",
|
41 |
+
"Access-Control-Allow-Methods": "*",
|
42 |
+
"Access-Control-Allow-Headers": "*",
|
43 |
+
},
|
44 |
+
// Enable gzip compression of generated files.
|
45 |
+
compress: true,
|
46 |
+
static: {
|
47 |
+
// By default WebpackDevServer serves physical files from current directory
|
48 |
+
// in addition to all the virtual build products that it serves from memory.
|
49 |
+
// This is confusing because those files won’t automatically be available in
|
50 |
+
// production build folder unless we copy them. However, copying the whole
|
51 |
+
// project directory is dangerous because we may expose sensitive files.
|
52 |
+
// Instead, we establish a convention that only files in `public` directory
|
53 |
+
// get served. Our build script will copy `public` into the `build` folder.
|
54 |
+
// In `index.html`, you can get URL of `public` folder with %PUBLIC_URL%:
|
55 |
+
// <link rel="icon" href="%PUBLIC_URL%/favicon.ico">
|
56 |
+
// In JavaScript code, you can access it with `process.env.PUBLIC_URL`.
|
57 |
+
// Note that we only recommend to use `public` folder as an escape hatch
|
58 |
+
// for files like `favicon.ico`, `manifest.json`, and libraries that are
|
59 |
+
// for some reason broken when imported through webpack. If you just want to
|
60 |
+
// use an image, put it in `src` and `import` it from JavaScript instead.
|
61 |
+
directory: paths.appPublic,
|
62 |
+
publicPath: [paths.publicUrlOrPath],
|
63 |
+
// By default files from `contentBase` will not trigger a page reload.
|
64 |
+
watch: {
|
65 |
+
// Reportedly, this avoids CPU overload on some systems.
|
66 |
+
// https://github.com/facebook/create-react-app/issues/293
|
67 |
+
// src/node_modules is not ignored to support absolute imports
|
68 |
+
// https://github.com/facebook/create-react-app/issues/1065
|
69 |
+
ignored: ignoredFiles(paths.appSrc),
|
70 |
+
},
|
71 |
+
},
|
72 |
+
client: {
|
73 |
+
webSocketURL: {
|
74 |
+
// Enable custom sockjs pathname for websocket connection to hot reloading server.
|
75 |
+
// Enable custom sockjs hostname, pathname and port for websocket connection
|
76 |
+
// to hot reloading server.
|
77 |
+
hostname: sockHost,
|
78 |
+
pathname: sockPath,
|
79 |
+
port: sockPort,
|
80 |
+
},
|
81 |
+
overlay: {
|
82 |
+
errors: true,
|
83 |
+
warnings: false,
|
84 |
+
},
|
85 |
+
},
|
86 |
+
devMiddleware: {
|
87 |
+
// It is important to tell WebpackDevServer to use the same "publicPath" path as
|
88 |
+
// we specified in the webpack config. When homepage is '.', default to serving
|
89 |
+
// from the root.
|
90 |
+
// remove last slash so user can land on `/test` instead of `/test/`
|
91 |
+
publicPath: paths.publicUrlOrPath.slice(0, -1),
|
92 |
+
},
|
93 |
+
|
94 |
+
https: getHttpsConfig(),
|
95 |
+
host,
|
96 |
+
historyApiFallback: {
|
97 |
+
// Paths with dots should still use the history fallback.
|
98 |
+
// See https://github.com/facebook/create-react-app/issues/387.
|
99 |
+
disableDotRule: true,
|
100 |
+
index: paths.publicUrlOrPath,
|
101 |
+
},
|
102 |
+
// `proxy` is run between `before` and `after` `webpack-dev-server` hooks
|
103 |
+
proxy,
|
104 |
+
onBeforeSetupMiddleware(devServer) {
|
105 |
+
// Keep `evalSourceMapMiddleware`
|
106 |
+
// middlewares before `redirectServedPath` otherwise will not have any effect
|
107 |
+
// This lets us fetch source contents from webpack for the error overlay
|
108 |
+
devServer.app.use(evalSourceMapMiddleware(devServer));
|
109 |
+
|
110 |
+
if (fs.existsSync(paths.proxySetup)) {
|
111 |
+
// This registers user provided middleware for proxy reasons
|
112 |
+
require(paths.proxySetup)(devServer.app);
|
113 |
+
}
|
114 |
+
},
|
115 |
+
onAfterSetupMiddleware(devServer) {
|
116 |
+
// Redirect to `PUBLIC_URL` or `homepage` from `package.json` if url not match
|
117 |
+
devServer.app.use(redirectServedPath(paths.publicUrlOrPath));
|
118 |
+
|
119 |
+
// This service worker file is effectively a 'no-op' that will reset any
|
120 |
+
// previous service worker registered for the same host:port combination.
|
121 |
+
// We do this in development to avoid hitting the production cache if
|
122 |
+
// it used the same host and port.
|
123 |
+
// https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432
|
124 |
+
devServer.app.use(noopServiceWorkerMiddleware(paths.publicUrlOrPath));
|
125 |
+
},
|
126 |
+
};
|
127 |
+
};
|