forked from navikt/syfomodiaperson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.dev.ts
49 lines (41 loc) · 1.23 KB
/
webpack.dev.ts
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
import { merge } from "webpack-merge";
import mockEndepunkter from "./mock/mockEndepunkter";
const express = require("express");
const common = require("./webpack.common.ts");
const path = require("path");
import * as Session from "./server/session";
module.exports = merge(common, {
mode: "development",
devtool: "eval-source-map",
devServer: {
port: 8080,
static: {
directory: path.join(__dirname, "dist"),
staticOptions: {
redirect: false,
},
},
setupMiddlewares: (middlewares: any, devServer: any) => {
setupDev(devServer);
return middlewares;
},
},
});
const setupDev = async (devServer: any) => {
const { app, compiler } = devServer;
await Session.setupSession(app);
mockEndepunkter(app);
app.use("/static", express.static(path.resolve(__dirname, "dist")));
app.use("*", (req: any, res: any) => {
const filename = path.join(compiler.outputPath, "index.html");
compiler.outputFileSystem.readFile(filename, (err: any, result: any) => {
if (err) {
res.status(404).sendFile(path.resolve(__dirname, "public/error.html"));
return;
}
res.set("Content-Type", "text/html");
res.send(result);
res.end();
});
});
};