-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
43 lines (33 loc) · 1.23 KB
/
server.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
const express = require("express")
const http = require("http")
const path = require("path")
const watch = require("node-watch")
const {exec} = require("child_process")
const opn = require("opn")
function rebuildProject() {
// Call the build script
exec("node build")
}
// Rebuild project a first time to make sure everything is build
rebuildProject()
// Watch the src for changes to update the project
watch("src", {recursive: true}, rebuildProject)
// Also watch the templates so the reload includes these as well
watch("templates", {recursive: true}, rebuildProject)
// Build the express server to allow for static file serving
const app = express()
// Mark the public folder as the docs directory
const publicDir = path.join(__dirname, "docs")
// The server should run on port 3000
const PORT = process.env.PORT || 3000
// If the root web page is requested, serve index.html
app.get("/", (req, res) => {
res.sendFile(path.join(publicDir, "index.html"))
})
// For everything else, serve the public "build" folder defined above
app.use(express.static(publicDir))
const server = http.createServer(app)
server.listen(PORT, function () {
console.log("Development server listening on port " + PORT)
opn("http://localhost:" + PORT)
})