Fixed manual setup (alongside docker)

This commit is contained in:
Daniel
2022-06-21 20:23:17 +04:30
parent ace0135a11
commit ed0ab482a7
9 changed files with 38 additions and 44 deletions
+6 -6
View File
@@ -1,7 +1,7 @@
module.exports.port = process.env.PORT || 5000;
module.exports.URI = process.env.MONGODB_URI || 'mongodb://localhost:27017';
module.exports.database = process.env.DB_NAME || 'sample_db';
module.exports.collection = process.env.COLLECTION_NAME || 'list';
const storageLocation = process.env.STORAGE_LOCATION || '/media';
module.exports.screenshotDirectory = storageLocation + '/screenshots';
module.exports.pdfDirectory = storageLocation + '/pdfs';
module.exports.URI = process.env.MONGODB_URI || "mongodb://localhost:27017"; // URI
module.exports.database = process.env.DB_NAME || "sample_db"; // Database name
module.exports.collection = process.env.COLLECTION_NAME || "list"; // Collection name
const storageLocation = process.env.STORAGE_LOCATION || "./media";
module.exports.screenshotDirectory = storageLocation + "/screenshots";
module.exports.pdfDirectory = storageLocation + "/pdfs";
+21 -24
View File
@@ -4,7 +4,14 @@ const { MongoClient } = require("mongodb");
const cors = require("cors");
const getData = require("./modules/getData.js");
const fs = require("fs");
const { port, URI, database, collection, screenshotDirectory, pdfDirectory } = require("./config.js");
const {
port,
URI,
database,
collection,
screenshotDirectory,
pdfDirectory,
} = require("./config.js");
const fetch = require("cross-fetch");
const sanitize = require("sanitize-filename");
@@ -21,7 +28,6 @@ if (!fs.existsSync(pdfDirectory)) {
fs.mkdirSync(pdfDirectory, { recursive: true });
}
app.use(cors());
app.use(express.json());
@@ -33,7 +39,7 @@ app.get("/api", async (req, res) => {
app.get("/screenshots/:id", async (req, res) => {
res.sendFile(
screenshotDirectory + "/" + sanitize(req.params.id),
__dirname + "/" + screenshotDirectory + "/" + sanitize(req.params.id),
(err) => {
if (err) {
res.sendFile(__dirname + "/pages/404.html");
@@ -43,14 +49,11 @@ app.get("/screenshots/:id", async (req, res) => {
});
app.get("/pdfs/:id", async (req, res) => {
res.sendFile(
pdfDirectory + "/" + sanitize(req.params.id),
(err) => {
if (err) {
res.sendFile(__dirname + "/pages/404.html");
}
res.sendFile(pdfDirectory + "/" + sanitize(req.params.id), (err) => {
if (err) {
res.sendFile(__dirname + "/pages/404.html");
}
);
});
});
app.post("/api", async (req, res) => {
@@ -125,23 +128,17 @@ async function deleteDoc(doc) {
try {
const result = await list.deleteOne({ _id: doc });
fs.unlink(
screenshotDirectory + "/" + doc + ".png",
(err) => {
if (err) {
console.log(err);
}
fs.unlink(screenshotDirectory + "/" + doc + ".png", (err) => {
if (err) {
console.log(err);
}
);
});
fs.unlink(
pdfDirectory +"/" + doc + ".pdf",
(err) => {
if (err) {
console.log(err);
}
fs.unlink(pdfDirectory + "/" + doc + ".pdf", (err) => {
if (err) {
console.log(err);
}
);
});
return result;
} catch (err) {