forked from destinygg/chat-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
113 lines (109 loc) · 2.57 KB
/
webpack.config.js
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
require('dotenv').config();
const HtmlWebpackPlugin = require('html-webpack-plugin');
require('webpack');
/**
* Reads `sid` and `rememberme` session tokens from the environment and adds
* them to a request. Assumes the `Cookie` header is formatted `k1=v1; k2=v2`.
* @param {http.ClientRequest} request
*/
function bakeCookies(request) {
let cookies = request.getHeader('Cookie') ?? '';
const { SID, REMEMBERME } = process.env;
if (SID) {
if (cookies.indexOf('sid=') > -1) {
cookies = cookies.replace(/(sid=).*?(;|$)/, `$1${SID}$2`);
} else {
cookies += `sid=${SID}`;
}
}
if (REMEMBERME) {
cookies += `; rememberme=${REMEMBERME}`;
}
request.setHeader('Cookie', cookies);
}
module.exports = {
devServer: {
server: {
type: 'https',
},
port: 8282,
proxy: [
{
context: ['/api'],
target: 'https://www.destiny.gg',
secure: false,
changeOrigin: true,
onProxyReq: (proxyReq) => {
bakeCookies(proxyReq);
},
},
{
context: ['/cdn'],
target: 'https://cdn.destiny.gg',
pathRewrite: { '^/cdn': '' },
secure: false,
headers: {
Origin: 'https://www.destiny.gg',
Host: 'cdn.destiny.gg',
},
},
{
context: ['/chat'],
target: 'wss://chat.destiny.gg/ws',
pathRewrite: { '^/chat': '' },
secure: false,
ws: true,
headers: {
Origin: 'https://www.destiny.gg',
Host: 'chat.destiny.gg',
},
onProxyReqWs: (proxyReq) => {
bakeCookies(proxyReq);
},
},
],
},
entry: {
demo: './assets/demo.js',
},
watchOptions: {
ignored: /node_modules/,
},
plugins: [
new HtmlWebpackPlugin({
title: 'Destiny GG',
filename: 'index.html',
}),
],
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|)/,
loader: 'babel-loader',
options: { presets: ['@babel/preset-env'] },
},
{
test: /\.(scss|css)$/,
use: ['style-loader', 'css-loader', 'sass-loader', 'postcss-loader'],
},
{
test: /\.(png|jpg|gif|svg)$/,
type: 'asset/resource',
generator: { filename: 'img/[name][ext]' },
},
{
test: /\.(ttf)$/,
type: 'asset/resource',
generator: { filename: 'font/[name][ext]' },
},
{
test: /\.(html)$/,
loader: 'html-loader',
options: { minimize: true },
},
],
},
context: __dirname,
devtool: false,
};