-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
46 lines (35 loc) · 1011 Bytes
/
server.js
File metadata and controls
46 lines (35 loc) · 1011 Bytes
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
import express from "express";
import path from "path";
import webpack from "webpack";
import webpackMiddleware from "webpack-dev-middleware";
import webpackHotMiddleware from "webpack-hot-middleware";
import dotenv from "dotenv";
import webpackConfig from "./webpack.development.config.js";
const isLocal = !process.env._HANDLER;
const isDeploying = !!process.env.DEPLOYING;
const isDevelopment = isLocal && !isDeploying;
if (isLocal) {
dotenv.load();
}
const app = express();
if (isDevelopment) {
const compiler = webpack(webpackConfig);
app.use(
webpackMiddleware(compiler, {
noInfo: true,
publicPath: webpackConfig.output.publicPath,
})
);
app.use(webpackHotMiddleware(compiler));
}
app.set("view engine", "pug");
app.use(express.static(path.join(__dirname, "public")));
app.get("/", (req, res) => {
res.render("home", {
useBundledAssets: !isDevelopment,
});
});
if (isLocal && !isDeploying) {
app.listen(process.env.PORT || 3000);
}
module.exports = app;