diff --git a/myApp.js b/myApp.js index cad7930..c867152 100644 --- a/myApp.js +++ b/myApp.js @@ -79,31 +79,6 @@ TestApps[3] = class TestApp3 { } } -TestApps[4] = class TestApp { - #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.send(this.response(REQUEST, RESPONSE));}); - app.post(this.#paths[`API`][`now`], (REQUEST, RESPONSE, next) => {REQUEST.time = new Date(); next()}, (REQUEST, RESPONSE) => {RESPONSE.send(this.response(REQUEST, RESPONSE));}); - } - - /* Create the default response. */ - response(REQUEST, RESPONSE) { - let DEFAULT = {'time': REQUEST.time.toString()}; - return DEFAULT; - } - - constructor() { - this.handle(); - } -} - class TestApp { test() { diff --git a/scripts/time_server.js b/scripts/time_server.js new file mode 100644 index 0000000..f932339 --- /dev/null +++ b/scripts/time_server.js @@ -0,0 +1,31 @@ +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; \ No newline at end of file diff --git a/server.js b/server.js index f0f55fe..33c1f72 100644 --- a/server.js +++ b/server.js @@ -4,7 +4,7 @@ * ***************************************************/ const bGround = require('fcc-express-bground'); -const myApp = require('./scripts/echo'); +const myApp = require('./scripts/time_server'); const express = require('express'); const app = express();