added exe

This commit is contained in:
2025-06-10 21:40:23 +02:00
parent 05ecb42de6
commit 64f28e0dc7
6 changed files with 138 additions and 136 deletions

BIN
backend/Cookbook-v1_0.exe Normal file

Binary file not shown.

View File

@@ -1 +0,0 @@
dfrg

View File

@@ -1 +0,0 @@
## 124

View File

@@ -1,25 +1,21 @@
{ {
"name": "cookbook", "name": "cookbook",
"version": "0.4", "version": "1.0.0",
"main": "server.js", "description": "With this express app you can create and manage recipies.",
"bin": "server.js", "bin": "server.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "start": "node server.js",
"start": "node server.js" "build": "pkg . --targets node18-win-x64 --output Cookbook-v1_0.exe"
}, },
"keywords": [],
"author": "Theis Gaedigk",
"license": "ISC",
"description": "",
"dependencies": { "dependencies": {
"ejs": "^3.1.10", "ejs": "^3.1.9",
"express": "^5.1.0", "express": "^4.18.2",
"marked": "^15.0.12" "marked": "^12.0.2"
}, },
"pkg": { "pkg": {
"assets": [ "assets": [
"public/**/*", "views/**/*",
"views/**/*" "routes/**/*"
] ]
} }
} }

View File

@@ -1,19 +1,32 @@
// set static variables // static variables
const express = require("express"); const express = require("express");
const app = express(); const app = express();
const fs = require("fs"); const fs = require("fs");
const path = require("path"); const path = require("path");
const marked = require("marked"); const marked = require("marked");
const basePath = process.pkg ? path.dirname(process.execPath) : __dirname;
app.set("view engine", "ejs"); app.set("view engine", "ejs");
// static files
app.use(express.static(path.join(basePath, "public")));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.get("/add", (req, res) => { app.get("/add", (req, res) => {
res.render("addRecipe/index"); res.render("addRecipe/index");
}); });
app.get("/", (req, res) => { app.get("/", (req, res) => {
// script to sync recipes // sync recipes
const recipesFolder = path.join(__dirname, "database/recipes"); const recipesFolder = path.join(basePath, "database", "recipes");
if (!fs.existsSync(recipesFolder)) {
fs.mkdirSync(recipesFolder, { recursive: true });
}
fs.readdir(recipesFolder, (err, files) => { fs.readdir(recipesFolder, (err, files) => {
if (err) { if (err) {
return res.status(500).send("Error by reading recipe files!"); return res.status(500).send("Error by reading recipe files!");
@@ -31,43 +44,39 @@ app.get("/", (req, res) => {
res.render("index", { recipes }); res.render("index", { recipes });
}); });
// script to render in markdown
}); });
// middleware for add recipe // create recipe
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
// add recipe script
app.post("/add/create-recipe", (req, res) => { app.post("/add/create-recipe", (req, res) => {
const { filename, content } = req.body; const { filename, content } = req.body;
const recipesFolder = path.join(basePath, "database", "recipes");
const directory = path.join(__dirname, "database/recipes"); if (!fs.existsSync(recipesFolder)) {
fs.mkdirSync(recipesFolder, { recursive: true });
if (!fs.existsSync(directory)) {
fs.mkdirSync(directory);
} }
const filePath = path.join(directory, `${filename}.txt`); const filePath = path.join(recipesFolder, `${filename}.txt`);
fs.writeFile(filePath, content, (err) => { fs.writeFile(filePath, content, (err) => {
if (err) { if (err) {
console.error(err); console.error(err);
return res return res
.status(500) .status(500)
.console.error("Error by creating file")
.send("Error by creating file. Please check browser console!"); .send("Error by creating file. Please check browser console!");
} }
res.render("success", { res.render("success", {
filename: filename, filename,
path: filePath, path: filePath,
}); });
}); });
}); });
// recipe router
const recipeRouter = require("./routes/recipes"); const recipeRouter = require("./routes/recipes");
app.use("/recipe", recipeRouter); app.use("/recipe", recipeRouter);
app.listen(3000); // start server
app.listen(3000, () => {
console.log("Server running at http://localhost:3000");
});

View File

@@ -4,7 +4,6 @@
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Add recipe</title> <title>Add recipe</title>
</head> </head>
<body> <body>
<main class="container"> <main class="container">
@@ -38,119 +37,119 @@
</html> </html>
<style> <style>
html { html {
font-family: -apple-system, BlinkMacSystemFont, "San Francisco", font-family: -apple-system, BlinkMacSystemFont, "San Francisco", "Segoe UI",
"Segoe UI", Roboto, Helvetica, Arial, sans-serif; Roboto, Helvetica, Arial, sans-serif;
} }
* { * {
box-sizing: border-box; box-sizing: border-box;
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
body { body {
background-color: #f5f5f7; background-color: #f5f5f7;
color: #1d1d1f; color: #1d1d1f;
font-size: 16px; font-size: 16px;
line-height: 1.5; line-height: 1.5;
min-height: 100vh; min-height: 100vh;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
padding: 2rem; padding: 2rem;
} }
.container { .container {
background-color: #ffffff; background-color: #ffffff;
padding: 2.5rem; padding: 2.5rem;
border-radius: 20px; border-radius: 20px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
width: 100%; width: 100%;
max-width: 600px; max-width: 600px;
} }
h1 { h1 {
font-size: 1.8rem; font-size: 1.8rem;
margin-bottom: 1.5rem; margin-bottom: 1.5rem;
font-weight: 600; font-weight: 600;
text-align: center; text-align: center;
} }
label { label {
display: block; display: block;
margin-top: 1.2rem; margin-top: 1.2rem;
margin-bottom: 0.5rem; margin-bottom: 0.5rem;
font-weight: 500; font-weight: 500;
} }
input[type="text"], input[type="text"],
textarea { textarea {
width: 100%; width: 100%;
padding: 0.75rem 1rem; padding: 0.75rem 1rem;
border: 1px solid #d1d1d6; border: 1px solid #d1d1d6;
border-radius: 12px; border-radius: 12px;
background-color: #f9f9fa; background-color: #f9f9fa;
font-size: 1rem; font-size: 1rem;
transition: border 0.2s ease; transition: border 0.2s ease;
} }
input[type="text"]:focus, input[type="text"]:focus,
textarea:focus { textarea:focus {
border-color: #007aff; border-color: #007aff;
outline: none; outline: none;
background-color: #fff; background-color: #fff;
} }
textarea { textarea {
resize: vertical; resize: vertical;
min-height: 150px; min-height: 150px;
} }
small { small {
display: block; display: block;
margin-top: 0.4rem; margin-top: 0.4rem;
color: #6e6e73; color: #6e6e73;
font-size: 0.875rem; font-size: 0.875rem;
} }
.button-group { .button-group {
margin-top: 2rem; margin-top: 2rem;
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
flex-wrap: wrap; flex-wrap: wrap;
gap: 1rem; gap: 1rem;
} }
button, button,
.back-btn { .back-btn {
padding: 0.75rem 1.5rem; padding: 0.75rem 1.5rem;
border: none; border: none;
border-radius: 12px; border-radius: 12px;
font-size: 1rem; font-size: 1rem;
font-weight: 500; font-weight: 500;
cursor: pointer; cursor: pointer;
transition: all 0.2s ease-in-out; transition: all 0.2s ease-in-out;
text-decoration: none; text-decoration: none;
text-align: center; text-align: center;
} }
button[type="submit"] { button[type="submit"] {
background-color: #007aff; background-color: #007aff;
color: white; color: white;
} }
button[type="submit"]:hover { button[type="submit"]:hover {
background-color: #005ecb; background-color: #005ecb;
} }
.back-btn { .back-btn {
background-color: #e5e5ea; background-color: #e5e5ea;
color: #1d1d1f; color: #1d1d1f;
} }
.back-btn:hover { .back-btn:hover {
background-color: #d1d1d6; background-color: #d1d1d6;
} }
</style> </style>