feat: add cors middleware

This commit is contained in:
alok8bb 2022-07-15 11:08:20 +05:30
parent 656c95519d
commit e0d867fe30
No known key found for this signature in database
GPG Key ID: 748A8580B906551C
4 changed files with 33 additions and 6 deletions

View File

@ -14,10 +14,12 @@
"@types/node": "^18.0.3",
"@types/pg": "^8.6.5",
"ts-node-dev": "^2.0.0",
"@types/cors": "^2.8.12",
"typescript": "^4.7.4"
},
"dependencies": {
"chalk": "^4.1.2",
"cors": "^2.8.5",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"pg": "^8.7.3"

21
pnpm-lock.yaml generated
View File

@ -1,10 +1,12 @@
lockfileVersion: 5.4
specifiers:
'@types/cors': ^2.8.12
'@types/express': ^4.17.13
'@types/node': ^18.0.3
'@types/pg': ^8.6.5
chalk: ^4.1.2
cors: ^2.8.5
dotenv: ^16.0.1
express: ^4.18.1
pg: ^8.7.3
@ -13,11 +15,13 @@ specifiers:
dependencies:
chalk: 4.1.2
cors: 2.8.5
dotenv: 16.0.1
express: 4.18.1
pg: 8.7.3
devDependencies:
'@types/cors': 2.8.12
'@types/express': 4.17.13
'@types/node': 18.0.3
'@types/pg': 8.6.5
@ -78,6 +82,10 @@ packages:
'@types/node': 18.0.3
dev: true
/@types/cors/2.8.12:
resolution: {integrity: sha512-vt+kDhq/M2ayberEtJcIN/hxXy1Pk+59g2FV/ZQceeaTyCtCucjL2Q7FXlFjtWn4n15KCr1NE2lNNFhp0lEThw==}
dev: true
/@types/express-serve-static-core/4.17.29:
resolution: {integrity: sha512-uMd++6dMKS32EOuw1Uli3e3BPgdLIXmezcfHv7N4c1s3gkhikBplORPpMq3fuWkxncZN1reb16d5n8yhQ80x7Q==}
dependencies:
@ -299,6 +307,14 @@ packages:
engines: {node: '>= 0.6'}
dev: false
/cors/2.8.5:
resolution: {integrity: sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==}
engines: {node: '>= 0.10'}
dependencies:
object-assign: 4.1.1
vary: 1.1.2
dev: false
/create-require/1.1.1:
resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==}
dev: true
@ -619,6 +635,11 @@ packages:
engines: {node: '>=0.10.0'}
dev: true
/object-assign/4.1.1:
resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==}
engines: {node: '>=0.10.0'}
dev: false
/object-inspect/1.12.2:
resolution: {integrity: sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ==}
dev: false

View File

@ -4,6 +4,7 @@ import BinRouter from "./routes/bin";
import { Client, Pool } from "pg";
import { createDataDir, errorHandler, logError, logSuccess } from "./utils";
import { tableExists, populateDB } from "./db";
import cors from "cors";
const main = async () => {
dotenv.config();
@ -33,8 +34,12 @@ const main = async () => {
const app: Express = express();
const port = process.env.PORT;
// FIX: other bodies panic
app.use(express.text());
// check more on this later
app.use(cors());
app.get("/", (req: Request, res: Response) => {
res.send("Hello, World!");
});

View File

@ -1,11 +1,10 @@
import { Router, Request, Response, NextFunction } from "express";
import { Pool, QueryResult } from "pg";
import path from "path";
import { Word } from "../utils/types";
import { Request, Response, Router } from "express";
import fsp from "fs/promises";
import { getPastePath, projectRoot } from "../utils";
import path from "path";
import { Pool } from "pg";
import { getAvailableWord, getWordFromVal, setWordTaken } from "../db/bin";
import { getPackedSettings } from "http2";
import { getPastePath, projectRoot } from "../utils";
import { Word } from "../utils/types";
export default function BinRouter(db: Pool) {
const router: Router = Router();