set up demo mode

This commit is contained in:
fred 2025-08-05 18:11:03 +00:00
parent 9aac6e0eff
commit 04bfdd0c8f
10 changed files with 93 additions and 16 deletions

View file

@ -10,7 +10,7 @@ app.use(express.json());
// ####### ROUTES #######
app.get("/backend/test", async (req, res) => {
console.log("test");
res.json({ test: "test" });
res.json({ env: process.env.NODE_ENV });
});
// ### GET ALL RECIPES ###
app.get("/backend/recipes", async (req, res) => {
@ -81,6 +81,7 @@ app.get("/backend/recipe/:id", async (req, res) => {
// ### ADD RECIPE ###
app.post("/backend/add-recipe", async (req, res) => {
if (process.env.NODE_ENV === 'demo') { return; };
const { name, author, cuisine, stars, ingredients, steps, prep_minutes, cook_minutes } = req.body;
try {
const [id] = await db("recipes").insert(
@ -118,6 +119,7 @@ app.post("/backend/add-recipe", async (req, res) => {
// ### SET STARS ###
app.post("/backend/set-stars", async (req, res) => {
if (process.env.NODE_ENV === 'demo') { return; };
const { id, stars } = req.body;
try {
await db("recipes").where({ id: id }).update({ stars: stars });
@ -130,6 +132,7 @@ app.post("/backend/set-stars", async (req, res) => {
// ### DELETE RECIPE ###
app.delete("/backend/delete-recipe", async (req, res) => {
if (process.env.NODE_ENV === 'demo') { return; };
const { id } = req.body;
try {
await db("recipe_steps").where({ recipe_id: id }).del();

View file

@ -20,6 +20,25 @@ module.exports = {
},
},
demo: {
client: "postgresql",
connection: {
host: "db",
port: process.env.DB_PORT,
database: process.env.DB_NAME,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
},
pool: {
min: 2,
max: 10,
},
migrations: {
tableName: "knex_migrations",
directory: "./migrations",
},
},
production: {
client: "postgresql",
connection: {

View file

@ -3,8 +3,8 @@
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "node backendServer.js",
"demo": "node backendServer.js",
"production": "node backendServer.js"
},
"keywords": [],