diff --git a/server/.env b/server/.env index bff0625..c663bad 100644 --- a/server/.env +++ b/server/.env @@ -4,6 +4,7 @@ # Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB. # See the documentation for all the connection string options: https://pris.ly/d/connection-strings +ENVIRONMENT=dev PORT=8080 FRONTEND_URL="http://localhost:3000" DATABASE_URL="file:./dev.db" \ No newline at end of file diff --git a/server/package-lock.json b/server/package-lock.json index 603cf2c..d570ecc 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -10,11 +10,13 @@ "license": "MIT", "dependencies": { "@prisma/client": "^3.15.2", + "cors": "^2.8.5", "dotenv": "^16.0.1", "express": "^4.18.1", "sqlite3": "^5.0.8" }, "devDependencies": { + "@types/cors": "^2.8.12", "@types/express": "^4.17.13", "@types/node": "^18.0.0", "@types/sqlite3": "^3.1.8", @@ -245,6 +247,12 @@ "@types/node": "*" } }, + "node_modules/@types/cors": { + "version": "2.8.12", + "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.12.tgz", + "integrity": "sha512-vt+kDhq/M2ayberEtJcIN/hxXy1Pk+59g2FV/ZQceeaTyCtCucjL2Q7FXlFjtWn4n15KCr1NE2lNNFhp0lEThw==", + "dev": true + }, "node_modules/@types/express": { "version": "4.17.13", "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.13.tgz", @@ -961,6 +969,18 @@ "integrity": "sha512-JxbCBUdrfr6AQjOXrxoTvAMJO4HBTUIlBzslcJPAz+/KT8yk53fXun51u+RenNYvad/+Vc2DIz5o9UxlCDymFQ==", "dev": true }, + "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/create-require": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", @@ -4234,6 +4254,12 @@ "@types/node": "*" } }, + "@types/cors": { + "version": "2.8.12", + "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.12.tgz", + "integrity": "sha512-vt+kDhq/M2ayberEtJcIN/hxXy1Pk+59g2FV/ZQceeaTyCtCucjL2Q7FXlFjtWn4n15KCr1NE2lNNFhp0lEThw==", + "dev": true + }, "@types/express": { "version": "4.17.13", "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.13.tgz", @@ -4795,6 +4821,15 @@ "integrity": "sha512-JxbCBUdrfr6AQjOXrxoTvAMJO4HBTUIlBzslcJPAz+/KT8yk53fXun51u+RenNYvad/+Vc2DIz5o9UxlCDymFQ==", "dev": true }, + "cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "requires": { + "object-assign": "^4", + "vary": "^1" + } + }, "create-require": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", diff --git a/server/package.json b/server/package.json index d6bdb68..ecdfa47 100644 --- a/server/package.json +++ b/server/package.json @@ -12,11 +12,13 @@ "license": "MIT", "dependencies": { "@prisma/client": "^3.15.2", + "cors": "^2.8.5", "dotenv": "^16.0.1", "express": "^4.18.1", "sqlite3": "^5.0.8" }, "devDependencies": { + "@types/cors": "^2.8.12", "@types/express": "^4.17.13", "@types/node": "^18.0.0", "@types/sqlite3": "^3.1.8", diff --git a/server/server.ts b/server/server.ts index 76d2587..ca3618f 100644 --- a/server/server.ts +++ b/server/server.ts @@ -1,11 +1,20 @@ import "dotenv/config"; import express, { Express, Request, Response } from "express"; +import cors from "cors"; import { PrismaClient, EncryptedNote } from "@prisma/client"; const prisma = new PrismaClient(); const app: Express = express(); +if (process.env.ENVIRONMENT == "dev") { + app.use( + cors({ + origin: "*", + }) + ); +} + app.use(express.json()); // start the Express server @@ -13,12 +22,6 @@ app.listen(process.env.PORT, () => { console.log(`server started at http://localhost:${process.env.PORT}`); }); -// type EncryptedNote = { -// id?: string; -// ciphertext: string; -// hmac: string; -// }; - // Post new encrypted note app.post("/note/", async (req: Request<{}, {}, EncryptedNote>, res) => { const note = req.body; diff --git a/webapp/src/lib/components/navbar/NavBar.svelte b/webapp/src/lib/components/navbar/NavBar.svelte index 61a5e88..efd728b 100644 --- a/webapp/src/lib/components/navbar/NavBar.svelte +++ b/webapp/src/lib/components/navbar/NavBar.svelte @@ -6,7 +6,7 @@