-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
46 lines (34 loc) · 1.34 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
43
44
45
/* server.js - Express server*/
'use strict';
const log = console.log
log('Express server')
const express = require('express')
const app = express();
const path = require('path');
/*** Webpage routes below **********************************/
/// We only allow specific parts of our public directory to be access, rather than giving
/// access to the entire directory.
// static js directory
app.use("/js", express.static(path.join(__dirname, '/pub/js')))
// static css directory
app.use("/css", express.static(path.join(__dirname, '/pub/css')))
// route for root
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '/pub/html/index.html'))
})
app.get('/examples.html', (req, res) => {
res.sendFile(path.join(__dirname, '/pub/html/examples.html'))
})
app.get('/api-browkit.html', (req, res) => {
res.sendFile(path.join(__dirname, '/pub/html/api-browkit.html'))
})
app.get('/index.html', (req, res) => {
res.sendFile(path.join(__dirname, '/pub/html/index.html'))
})
// will use an 'environmental variable', process.env.PORT, for deployment.
const port = process.env.PORT || 5000
app.listen(port, () => {
log(`Listening on port ${port}...`)
}) // localhost development port 5000 (http://localhost:5000)
// We've bound that port to localhost to go to our express server.
// Must restart web server when you make changes to route handlers.