-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
92 lines (86 loc) · 2.69 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
// TO DISCUSS:
//
// With randomized IDs, we could have a single code labs project.
// Seems like a business decision around friction vs. name capture
// Also, could randomize segment if they can be lazy created
const ironCoreConfig = require("./ironcore-config.json");
const webpack = require("webpack");
const path = require("path");
const fs = require("fs");
const jwt = require("jsonwebtoken");
const privateKey = fs.readFileSync(path.join(__dirname, "private.key"), "utf8");
/**
* Generate a JWT token using the current requesting users ID, your project ID (pid) and segment ID (sid). Return
* the generated token back to the client.
*/
function serveJWT(req, res) {
const {userID} = req.params;
if (!userID) {
res.status(404).end();
} else {
const token = jwt.sign(
{
pid: ironCoreConfig.projectId,
sid: ironCoreConfig.segmentId,
kid: ironCoreConfig.serviceKeyId,
},
privateKey,
{
algorithm: "ES256",
expiresIn: "2m",
subject: userID,
}
);
res.status(200).send(token);
}
}
module.exports = (env) => {
return {
devServer: {
port: 3000,
hot: true,
setupMiddlewares: (middlewares, devServer) => {
devServer.app.get("/generateJWT/:userID", serveJWT);
devServer.app.get("/", (req, res) =>
res.sendFile("index.html", {
root: __dirname,
})
);
return middlewares;
},
static: [
{
directory: path.join(__dirname, "css"),
},
],
},
mode: "development",
entry: ["whatwg-fetch", "babel-polyfill", `./app/${env.stage}/get-started-by-writing-me.js`],
output: {
publicPath: "http://localhost:3000/static/dist/",
filename: "[name].js",
},
resolve: {
modules: ["app", "node_modules"],
extensions: [".js"],
},
devtool: "cheap-module-source-map",
module: {
rules: [
{
test: /\.js$/,
use: [
{
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"],
},
},
],
exclude: /node_modules/,
},
],
},
plugins: [new webpack.NoEmitOnErrorsPlugin()],
};
};