Give back answers from backend based on inputs from frontend

Viewed 86

I want to give back an answer form the backend to the frontend whenever "Hallo" is given as an input form the frontend, if the input is not "Hallo" nothing should be given back

import { opine } from "https://deno.land/x/opine@2.1.1/mod.ts";
import { opineCors } from "https://deno.land/x/cors/mod.ts";
const app = opine();
app.use(opineCors())

app.get("/gibmirdieloesung", function (req, res) {
    console.log(require("Hallo").inspect(req.params))
    res.send({ answer: "This is an example" });
});

app.listen(
    3004,
    () => console.log("server has started on http://localhost:3004 "),
);

Is the usage of require() correct? If not, do you have any suggestions?

Thank U

1 Answers

I removed the require and inspect and changed the response a little.

Now when requesting http://localhost:3004/hello?a=1&b=2 using the code below

#!/usr/bin/env deno run --allow-read --allow-net

import { opine } from "https://deno.land/x/opine@2.1.1/mod.ts";
import { opineCors } from "https://deno.land/x/cors/mod.ts";
const app = opine();
app.use(opineCors())

app.get("/hello", function (req, res) {
    console.log(req.query);
    let r = req.query;
    r.answer = "This is an example";
    res.send(r);
});

app.listen(
    3004,
    () => console.log("server has started on http://localhost:3004 "),
);

I get {"a":"1","b":"2","answer":"This is an example"} as a response.

Related