From c841311ad750ce2b9ef108769342199b08912727 Mon Sep 17 00:00:00 2001 From: buzzcode2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Sat, 8 Mar 2025 09:39:53 +0000 Subject: [PATCH] =?UTF-8?q?Complete=20task=20=E2=80=9CGet=20Route=20Parame?= =?UTF-8?q?ter=20Input=20from=20the=20Client=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/echo.js | 41 +++++++++++++++++++++++++++++++++++++++++ server.js | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 scripts/echo.js 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();