-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
35 lines (30 loc) · 906 Bytes
/
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
// Requires
const express = require('express');
const fs = require('node:fs');
const path = require('path');
/**
* Serves content statically in the given app from
* the directory at `staticContentDir`
* @param {Express} expressAppInstance
* @param {String} staticContentDir
*/
function serveStatic(expressAppInstance, staticContentDir)
{
expressAppInstance.use(
`/${staticContentDir}`,
express.static(path.join(__dirname, staticContentDir))
);
}
// Create app instance
const app = express();
// Allow static serving from these folders
serveStatic(app, 'ngineer_js/target');
serveStatic(app, 'ngineer_js');
serveStatic(app, '');
// Serve content at root
app.get('/', (req, res) => {
const html = fs.readFileSync('index.html', 'utf8');
res.send(html);
});
// Start server
app.listen(3000, () => console.log('Ngineer is listening on port 3000.'));