comp review todo app update (#146)
* new todo frontend * yarn --> npm * basic Dockerfile * add Helm chart for todo list * backend working * connect new-app'd frontend to backend via proxy_pass * move nginx conf * move nginx conf back * move helm chart to course repo * add simple SSR node.js service * log error message * fix host typo * fix dockerfiles * add link to items page * improve probe route for todo-backend * canary probe route for todo-backend * Dockerfile -> Containerfile todo-backend * Dockerfile -> Containerfile todo-frontend * remove commands for containerfile as part of comp review
This commit is contained in:
30
todo-ssr/index.js
Normal file
30
todo-ssr/index.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const express = require("express");
|
||||
const axios = require("axios");
|
||||
|
||||
const port = Number(process.env.PORT || 8080);
|
||||
const apiHost = process.env.API_HOST || "localhost:3000";
|
||||
|
||||
const app = express();
|
||||
|
||||
app.set("view engine", "pug");
|
||||
|
||||
app.get("/", (req, res) => {
|
||||
res.render("index", { title: "Hello", message: "Page message" });
|
||||
});
|
||||
|
||||
app.get("/items", async (req, res) => {
|
||||
try {
|
||||
const items = await axios
|
||||
.get(`${apiHost}/api/items`)
|
||||
.then((response) => response.data);
|
||||
console.log("items:", items);
|
||||
res.render("items", { items });
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
res.status(500).send(err.message);
|
||||
}
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log("Express server started on port: " + port);
|
||||
});
|
||||
Reference in New Issue
Block a user