From ce72dd40a836d1515de8e9534f6829dd832d3849 Mon Sep 17 00:00:00 2001 From: leca Date: Sat, 18 Nov 2023 14:12:46 +0300 Subject: [PATCH] added cors --- package-lock.json | 21 +++++++++++++++++++++ package.json | 4 +++- src/index.js | 6 ++++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4512cf2..d9fe0cc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@vitejs/plugin-vue": "^4.4.1", "axios": "^1.6.1", "bcryptjs": "^2.4.3", + "cors": "^2.8.5", "dotenv": "^16.3.1", "ejs": "^3.1.9", "express": "^4.18.2", @@ -779,6 +780,18 @@ "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==" }, + "node_modules/cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/csstype": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.2.tgz", @@ -1531,6 +1544,14 @@ "node": ">=0.10.0" } }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/object-inspect": { "version": "1.13.1", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.1.tgz", diff --git a/package.json b/package.json index b762db7..91b3fe0 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "dev": "nodemon src/index.js & vite --host", "build": "vite build", "preview": "vite preview", - "start": "node src/index.js & vite --host" + "start": "node src/index.js & vite --host", + "back": "nodemon src/index.js" }, "repository": { "type": "git", @@ -22,6 +23,7 @@ "@vitejs/plugin-vue": "^4.4.1", "axios": "^1.6.1", "bcryptjs": "^2.4.3", + "cors": "^2.8.5", "dotenv": "^16.3.1", "ejs": "^3.1.9", "express": "^4.18.2", diff --git a/src/index.js b/src/index.js index 10f7af6..0ebb962 100644 --- a/src/index.js +++ b/src/index.js @@ -6,6 +6,7 @@ const MemoryStore = require('memorystore')(session); const fs = require('fs'); const bcrypt = require('bcryptjs'); // const fileupload = require('express-fileupload'); +const cors = require('cors'); const app = express(); @@ -50,7 +51,7 @@ let tokens = {}; app.use(express.urlencoded({ extended: true })) app.use(express.json()) - +app.use(cors()); app.use(session({ secret: process.env.SESSION_SECRET, @@ -150,6 +151,7 @@ app.get('/api/getBoards', async (req, res) => { res.setHeader('Content-Type', 'application/json'); res.end(JSON.stringify(queryRes.rows)); + // res.json(JSON.stringify(queryRes.rows)); }); app.post('/api/login', async (req, res) => { @@ -209,7 +211,7 @@ app.listen(process.env.APP_PORT, () => { const validateThread = (threadName, isLocked, isPinned, content, options, boardOptions, isAdmin) => { if ((isPinned || isLocked) && !isAdmin) return "Нет прав на выставление админских флагов"; - if (!content) return "Нельзя создать тред без текста"; + if (!content && boardOptions.requireContentForThreadCreation) return "Нельзя создать тред без текста"; //TODO: check if image is required return 'ok'