-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.class.js
48 lines (44 loc) · 1.14 KB
/
server.class.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
46
47
48
/**
* This is a basic Express server. We'll build in this class in future
* modules.
* @class
*/
class Server {
constructor() {
this.express = require('express');
this.app = this.express();
this.setupRoutes();
this.startServer();
}
/**
* Sets up the necessary routing.
*/
setupRoutes() {
this.setupStaticRoutes();
}
/**
* Creates the static routes.
*/
setupStaticRoutes() {
this.app.use(this.express.static(__dirname + '/'));
}
/**
* Starts an Express.js server. If port 3000 is not open, throws an error.
* @return {Promise} A promise that resolves when the server is up, throws
* if port 3000 is occupied or some other error occurs.
*/
startServer() {
return new Promise((resolve, reject) => {
try {
this.app.listen(3000, function() {
console.info('Server listening on port 3000');
resolve();
});
} catch(e) {
console.warn()
reject(e);
}
});
}
}
module.exports = Server;