mirror of
https://github.com/okiba-org/backend.git
synced 2025-04-23 19:06:55 +00:00
feat: add cors middleware
This commit is contained in:
parent
656c95519d
commit
e0d867fe30
@ -14,10 +14,12 @@
|
|||||||
"@types/node": "^18.0.3",
|
"@types/node": "^18.0.3",
|
||||||
"@types/pg": "^8.6.5",
|
"@types/pg": "^8.6.5",
|
||||||
"ts-node-dev": "^2.0.0",
|
"ts-node-dev": "^2.0.0",
|
||||||
|
"@types/cors": "^2.8.12",
|
||||||
"typescript": "^4.7.4"
|
"typescript": "^4.7.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chalk": "^4.1.2",
|
"chalk": "^4.1.2",
|
||||||
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^16.0.1",
|
"dotenv": "^16.0.1",
|
||||||
"express": "^4.18.1",
|
"express": "^4.18.1",
|
||||||
"pg": "^8.7.3"
|
"pg": "^8.7.3"
|
||||||
|
21
pnpm-lock.yaml
generated
21
pnpm-lock.yaml
generated
@ -1,10 +1,12 @@
|
|||||||
lockfileVersion: 5.4
|
lockfileVersion: 5.4
|
||||||
|
|
||||||
specifiers:
|
specifiers:
|
||||||
|
'@types/cors': ^2.8.12
|
||||||
'@types/express': ^4.17.13
|
'@types/express': ^4.17.13
|
||||||
'@types/node': ^18.0.3
|
'@types/node': ^18.0.3
|
||||||
'@types/pg': ^8.6.5
|
'@types/pg': ^8.6.5
|
||||||
chalk: ^4.1.2
|
chalk: ^4.1.2
|
||||||
|
cors: ^2.8.5
|
||||||
dotenv: ^16.0.1
|
dotenv: ^16.0.1
|
||||||
express: ^4.18.1
|
express: ^4.18.1
|
||||||
pg: ^8.7.3
|
pg: ^8.7.3
|
||||||
@ -13,11 +15,13 @@ specifiers:
|
|||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
chalk: 4.1.2
|
chalk: 4.1.2
|
||||||
|
cors: 2.8.5
|
||||||
dotenv: 16.0.1
|
dotenv: 16.0.1
|
||||||
express: 4.18.1
|
express: 4.18.1
|
||||||
pg: 8.7.3
|
pg: 8.7.3
|
||||||
|
|
||||||
devDependencies:
|
devDependencies:
|
||||||
|
'@types/cors': 2.8.12
|
||||||
'@types/express': 4.17.13
|
'@types/express': 4.17.13
|
||||||
'@types/node': 18.0.3
|
'@types/node': 18.0.3
|
||||||
'@types/pg': 8.6.5
|
'@types/pg': 8.6.5
|
||||||
@ -78,6 +82,10 @@ packages:
|
|||||||
'@types/node': 18.0.3
|
'@types/node': 18.0.3
|
||||||
dev: true
|
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:
|
/@types/express-serve-static-core/4.17.29:
|
||||||
resolution: {integrity: sha512-uMd++6dMKS32EOuw1Uli3e3BPgdLIXmezcfHv7N4c1s3gkhikBplORPpMq3fuWkxncZN1reb16d5n8yhQ80x7Q==}
|
resolution: {integrity: sha512-uMd++6dMKS32EOuw1Uli3e3BPgdLIXmezcfHv7N4c1s3gkhikBplORPpMq3fuWkxncZN1reb16d5n8yhQ80x7Q==}
|
||||||
dependencies:
|
dependencies:
|
||||||
@ -299,6 +307,14 @@ packages:
|
|||||||
engines: {node: '>= 0.6'}
|
engines: {node: '>= 0.6'}
|
||||||
dev: false
|
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:
|
/create-require/1.1.1:
|
||||||
resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==}
|
resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==}
|
||||||
dev: true
|
dev: true
|
||||||
@ -619,6 +635,11 @@ packages:
|
|||||||
engines: {node: '>=0.10.0'}
|
engines: {node: '>=0.10.0'}
|
||||||
dev: true
|
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:
|
/object-inspect/1.12.2:
|
||||||
resolution: {integrity: sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ==}
|
resolution: {integrity: sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ==}
|
||||||
dev: false
|
dev: false
|
||||||
|
@ -4,6 +4,7 @@ import BinRouter from "./routes/bin";
|
|||||||
import { Client, Pool } from "pg";
|
import { Client, Pool } from "pg";
|
||||||
import { createDataDir, errorHandler, logError, logSuccess } from "./utils";
|
import { createDataDir, errorHandler, logError, logSuccess } from "./utils";
|
||||||
import { tableExists, populateDB } from "./db";
|
import { tableExists, populateDB } from "./db";
|
||||||
|
import cors from "cors";
|
||||||
|
|
||||||
const main = async () => {
|
const main = async () => {
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
@ -33,8 +34,12 @@ const main = async () => {
|
|||||||
const app: Express = express();
|
const app: Express = express();
|
||||||
const port = process.env.PORT;
|
const port = process.env.PORT;
|
||||||
|
|
||||||
|
// FIX: other bodies panic
|
||||||
app.use(express.text());
|
app.use(express.text());
|
||||||
|
|
||||||
|
// check more on this later
|
||||||
|
app.use(cors());
|
||||||
|
|
||||||
app.get("/", (req: Request, res: Response) => {
|
app.get("/", (req: Request, res: Response) => {
|
||||||
res.send("Hello, World!");
|
res.send("Hello, World!");
|
||||||
});
|
});
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
import { Router, Request, Response, NextFunction } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
import { Pool, QueryResult } from "pg";
|
|
||||||
import path from "path";
|
|
||||||
import { Word } from "../utils/types";
|
|
||||||
import fsp from "fs/promises";
|
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 { 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) {
|
export default function BinRouter(db: Pool) {
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user