-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
37 lines (30 loc) · 811 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
36
37
const express = require('express');
const app = express();
const path = require('path');
const http = require('http');
const config = require('./config');
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'pages', 'index.html'));
});
app.get('/contact', (req, res) => {
res.sendFile(path.join(__dirname, 'pages', 'contact.html'));
});
app.get('/about', (req, res) => {
res.sendFile(path.join(__dirname, 'pages', 'about.html'));
});
const server = http.createServer(app);
function start(callback) {
server.listen(config.PORT, () => {
console.log(`Server started. Listening on port ${config.PORT}`);
if (callback !== undefined) return callback();
});
}
function stop() {
server.close(() => {
console.log('Server closed.');
});
}
module.exports = {
start,
stop
};