-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcorp.js
More file actions
115 lines (109 loc) · 2.71 KB
/
Copy pathcorp.js
File metadata and controls
115 lines (109 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* eslint-disable no-console */
const webpack = require("webpack");
const fs = require("fs");
const WebpackDevServer = require("webpack-dev-server");
const webpackConfig = require("./webpack.config");
const args = process.argv.slice(2);
let isHttps = false;
let isCorp = false;
let httpsPort = 443;
let httpPort = 9999;
let proxyPort = 9998;
const serverName = "0.0.0.0";
if (args.includes("--https")) isHttps = true;
if (args.includes("--corp")) isCorp = true;
console.log({ isCorp, isHttps });
function green(text) {
return "\u001b[1m\u001b[32m" + text + "\u001b[39m\u001b[22m";
}
function runFunc(err) {
if (err) {
console.log(err);
}
if (isCorp) {
if (isCorp) {
console.log("USE Shared array buffer test");
}
console.log(
green(
`Listening at ${
isHttps ? "https://localhost" : `http://127.0.0.1:${httpPort}`
}/index.html`,
),
);
}
console.log("USE No Shared array buffer test, use below link");
console.log(
green(
`Listening at http://127.0.0.1:${
isCorp ? proxyPort : httpPort
}/index.html`,
),
);
}
if (isCorp) {
new WebpackDevServer(
{
server: {
type: isHttps ? "https" : "http",
options: {
key: fs.readFileSync("build-scripts/localhost.key"),
cert: fs.readFileSync("build-scripts/localhost.crt"),
},
},
client: {
overlay: {
errors: false,
warnings: false,
runtimeErrors: false,
},
},
port: isHttps ? httpsPort : httpPort,
host: serverName,
static: "./",
headers: {
"Cross-Origin-Embedder-Policy": "credentialless",
"Cross-Origin-Opener-Policy": "same-origin",
"Cross-Origin-Resource-Policy": "cross-origin",
},
historyApiFallback: true,
proxy: !isHttps
? [
{
path: "/lib/iframe",
target: `http://127.0.0.1${proxyPort}/`,
},
]
: [],
allowedHosts: "all",
},
webpack(webpackConfig),
).start(isHttps ? httpsPort : httpPort, serverName);
}
new WebpackDevServer(
{
server: {
type: "http",
},
client: {
overlay: {
errors: false,
warnings: false,
runtimeErrors: false,
},
},
port: isCorp ? proxyPort : httpPort,
host: serverName,
static: "./",
headers: {
"Cross-Origin-Embedder-Policy": "unsafe-none",
"Cross-Origin-Opener-Policy": "unsafe-none",
},
open: isHttps
? "https://localhost/index.html"
: `http://127.0.0.1:${httpPort}/index.html`,
historyApiFallback: true,
},
webpack(webpackConfig),
).start(isCorp ? proxyPort : httpPort, serverName);
runFunc();