Created
June 12, 2021 16:21
-
-
Save mjzone/eed44e30e522d11c247f79af355c8ea3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const app = express(); | |
// Health check endpoint | |
app.get("/health", (req, res) => { | |
res.status(200); | |
res.send("healthy"); | |
}); | |
// Calculating the fibonacci value | |
let fib = (n) => { | |
if (n <= 1) return n; | |
return fib(n - 1) + fib(n - 2); | |
} | |
app.get("/generate/:number", (req, res) => { | |
let output = 0; | |
try { | |
const number = parseInt(req.params.number); | |
if (number) { | |
output = fib(number); | |
} | |
} catch (e) { | |
res.send("Error"); | |
} | |
res.json({ output }); | |
}); | |
app.listen(80, () => { | |
console.log("App listening on port 80!"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment