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:
@@ -17,7 +17,6 @@ RUN cd /opt/app-root/src && \
|
||||
ENV DATABASE_SVC=192.168.0.10
|
||||
ENV DATABASE_PORT=3306
|
||||
ENV DATABASE_PASSWORD=secret-pass
|
||||
ENV DATABASE_INIT=true
|
||||
ENV PORT=3000
|
||||
|
||||
EXPOSE 3000
|
||||
12
todo-backend/package-lock.json
generated
12
todo-backend/package-lock.json
generated
@@ -2878,9 +2878,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/normalize-url": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.0.tgz",
|
||||
"integrity": "sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ==",
|
||||
"version": "4.5.1",
|
||||
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.1.tgz",
|
||||
"integrity": "sha512-9UZCFRHQdNrfTpGg8+1INIg93B6zE0aXMVFkw1WFwvO4SlZywU6aLg5Of0Ap/PgcbSw4LNxvMWXMeugwMCX0AA==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
@@ -6461,9 +6461,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"normalize-url": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.0.tgz",
|
||||
"integrity": "sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ==",
|
||||
"version": "4.5.1",
|
||||
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.1.tgz",
|
||||
"integrity": "sha512-9UZCFRHQdNrfTpGg8+1INIg93B6zE0aXMVFkw1WFwvO4SlZywU6aLg5Of0Ap/PgcbSw4LNxvMWXMeugwMCX0AA==",
|
||||
"dev": true
|
||||
},
|
||||
"object-assign": {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import cookieParser from "cookie-parser";
|
||||
import express, { Request, Response } from "express";
|
||||
import express from "express";
|
||||
import "express-async-errors";
|
||||
import cors from "cors";
|
||||
import { Sequelize } from "sequelize";
|
||||
@@ -17,6 +17,8 @@ app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
app.use(cookieParser());
|
||||
|
||||
let canary = true;
|
||||
|
||||
const sequelize = new Sequelize(dbConnectionOptions);
|
||||
sequelize
|
||||
.authenticate()
|
||||
@@ -24,20 +26,20 @@ sequelize
|
||||
console.log("Connection has been established successfully.");
|
||||
})
|
||||
.catch((err) => {
|
||||
canary = false;
|
||||
console.error("Unable to connect to the database:", err);
|
||||
});
|
||||
|
||||
app.get("/", (req, res) => {
|
||||
if (canary) {
|
||||
res.send("OK");
|
||||
} else {
|
||||
res.status(500).send("Experienced an error on startup.");
|
||||
}
|
||||
});
|
||||
|
||||
// Add APIs
|
||||
app.use("/api", BaseRouter);
|
||||
|
||||
// Print API errors
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
app.use((err: Error, req: Request, res: Response) => {
|
||||
console.error(err, true);
|
||||
return res.status(500).json({
|
||||
error: err.message,
|
||||
});
|
||||
});
|
||||
|
||||
// Export express instance
|
||||
export default app;
|
||||
|
||||
@@ -37,9 +37,9 @@ export const TodoItem = sequelize.define<TodoItemInstance>(
|
||||
);
|
||||
|
||||
// (re-)creates table (NOT database)
|
||||
if (process.env.DATABASE_INIT === "true") {
|
||||
TodoItem.sync({ force: true });
|
||||
}
|
||||
// if (process.env.DATABASE_INIT === "true") {
|
||||
TodoItem.sync({ force: true });
|
||||
// }
|
||||
|
||||
export async function createTodoItem(todoItem: TodoItemCreationAttributes) {
|
||||
return TodoItem.create(todoItem).then((item) => item.get());
|
||||
|
||||
Reference in New Issue
Block a user