diff --git a/scripts/echo.js b/scripts/echo.js new file mode 100644 index 0000000..318bc1e --- /dev/null +++ b/scripts/echo.js @@ -0,0 +1,41 @@ +let express = require('express'); +require('dotenv').config(); +let app = express(); + + + + +class EchoServer { + #paths = { + "API": { + "echo": "/:word/echo" + } + } + + /* Echo. + + WORD (string): The data to be repeated. + returns: (object) the formatted repeat response + */ + echo(WORD) { + let RESPONSE = {"echo": WORD}; + return (RESPONSE); + } + + /* Create the response. + + REQUEST (object): The request object. + RESPONSE (object): The response object. + */ + respond(REQUEST, RESPONSE) { + RESPONSE.json(this.echo(REQUEST.params.word)); + } + + constructor() { + app.get(this.#paths[`API`][`echo`], (REQUEST, RESPONSE, next) => {this.respond(REQUEST, RESPONSE);}) + } +} + +new EchoServer(); + +module.exports = app; diff --git a/server.js b/server.js index 575f3f3..f0f55fe 100644 --- a/server.js +++ b/server.js @@ -4,7 +4,7 @@ * ***************************************************/ const bGround = require('fcc-express-bground'); -const myApp = require('./myApp'); +const myApp = require('./scripts/echo'); const express = require('express'); const app = express();