added exe
This commit is contained in:
BIN
backend/Cookbook-v1_0.exe
Normal file
BIN
backend/Cookbook-v1_0.exe
Normal file
Binary file not shown.
@@ -1 +0,0 @@
|
||||
dfrg
|
@@ -1 +0,0 @@
|
||||
## 124
|
@@ -1,25 +1,21 @@
|
||||
{
|
||||
"name": "cookbook",
|
||||
"version": "0.4",
|
||||
"main": "server.js",
|
||||
"version": "1.0.0",
|
||||
"description": "With this express app you can create and manage recipies.",
|
||||
"bin": "server.js",
|
||||
"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": {
|
||||
"ejs": "^3.1.10",
|
||||
"express": "^5.1.0",
|
||||
"marked": "^15.0.12"
|
||||
"ejs": "^3.1.9",
|
||||
"express": "^4.18.2",
|
||||
"marked": "^12.0.2"
|
||||
},
|
||||
"pkg": {
|
||||
"assets": [
|
||||
"public/**/*",
|
||||
"views/**/*"
|
||||
"views/**/*",
|
||||
"routes/**/*"
|
||||
]
|
||||
}
|
||||
}
|
@@ -1,19 +1,32 @@
|
||||
// set static variables
|
||||
// static variables
|
||||
const express = require("express");
|
||||
const app = express();
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const marked = require("marked");
|
||||
|
||||
const basePath = process.pkg ? path.dirname(process.execPath) : __dirname;
|
||||
|
||||
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) => {
|
||||
res.render("addRecipe/index");
|
||||
});
|
||||
|
||||
app.get("/", (req, res) => {
|
||||
// script to sync recipes
|
||||
const recipesFolder = path.join(__dirname, "database/recipes");
|
||||
// sync recipes
|
||||
const recipesFolder = path.join(basePath, "database", "recipes");
|
||||
|
||||
if (!fs.existsSync(recipesFolder)) {
|
||||
fs.mkdirSync(recipesFolder, { recursive: true });
|
||||
}
|
||||
|
||||
fs.readdir(recipesFolder, (err, files) => {
|
||||
if (err) {
|
||||
return res.status(500).send("Error by reading recipe files!");
|
||||
@@ -31,43 +44,39 @@ app.get("/", (req, res) => {
|
||||
|
||||
res.render("index", { recipes });
|
||||
});
|
||||
|
||||
// script to render in markdown
|
||||
});
|
||||
|
||||
// middleware for add recipe
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
app.use(express.json());
|
||||
|
||||
// add recipe script
|
||||
// create recipe
|
||||
app.post("/add/create-recipe", (req, res) => {
|
||||
const { filename, content } = req.body;
|
||||
const recipesFolder = path.join(basePath, "database", "recipes");
|
||||
|
||||
const directory = path.join(__dirname, "database/recipes");
|
||||
|
||||
if (!fs.existsSync(directory)) {
|
||||
fs.mkdirSync(directory);
|
||||
if (!fs.existsSync(recipesFolder)) {
|
||||
fs.mkdirSync(recipesFolder, { recursive: true });
|
||||
}
|
||||
|
||||
const filePath = path.join(directory, `${filename}.txt`);
|
||||
const filePath = path.join(recipesFolder, `${filename}.txt`);
|
||||
|
||||
fs.writeFile(filePath, content, (err) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return res
|
||||
.status(500)
|
||||
.console.error("Error by creating file")
|
||||
.send("Error by creating file. Please check browser console!");
|
||||
}
|
||||
|
||||
res.render("success", {
|
||||
filename: filename,
|
||||
filename,
|
||||
path: filePath,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// recipe router
|
||||
const recipeRouter = require("./routes/recipes");
|
||||
|
||||
app.use("/recipe", recipeRouter);
|
||||
|
||||
app.listen(3000);
|
||||
// start server
|
||||
app.listen(3000, () => {
|
||||
console.log("Server running at http://localhost:3000");
|
||||
});
|
||||
|
@@ -4,7 +4,6 @@
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Add recipe</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<main class="container">
|
||||
@@ -39,8 +38,8 @@
|
||||
|
||||
<style>
|
||||
html {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "San Francisco",
|
||||
"Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "San Francisco", "Segoe UI",
|
||||
Roboto, Helvetica, Arial, sans-serif;
|
||||
}
|
||||
|
||||
* {
|
||||
|
Reference in New Issue
Block a user