-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (31 loc) · 757 Bytes
/
server.js
File metadata and controls
32 lines (31 loc) · 757 Bytes
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
/* eslint valid-jsdoc: off*/
const express = require('express');
const redirect = new express.Router();
redirect.use((req, res, next)=>{
req.url = (req.url+'.json').toLowerCase();
next();
});
/**
* Creates an express server that serves the endpoints
*/
class Server {
/**
* Initializes a server emulating the API
* @param {*} [app] Express App
*/
constructor(app) {
this.app = app || express();
this.app.use('*', redirect);
this.app.use(express.static(__dirname+'/endpoints/'));
this.app.get('*', (req, res)=>{
res.send('{"success":false,"cause":"Unknown endpoint"}');
});
}
/**
* Shortcut for this.app.listen
*/
listen(...args) {
return this.app.listen(...args);
}
}
module.exports = Server;