fcc-boilerplate-express/scripts/time_server.js

31 lines
No EOL
680 B
JavaScript

let express = require('express');
require('dotenv').config();
let app = express();
class TimeServer {
#paths = {
"API": {
"now": "/now"
}
}
/* Handle API responses.
*/
handle() {
app.get(this.#paths[`API`][`now`], (REQUEST, RESPONSE, next) => {REQUEST.time = new Date(); next()}, (REQUEST, RESPONSE) => {RESPONSE.json(this.response(REQUEST, RESPONSE));});
}
/* Create the default response. */
response(REQUEST, RESPONSE) {
let DEFAULT = {'time': REQUEST.time.toString()};
return DEFAULT;
}
constructor() {
this.handle();
}
}
new TimeServer();
module.exports = app;