Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

Commit f9b9dc4

Browse files
committed
fix(server): use cors lib
1 parent 5b66b8d commit f9b9dc4

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

frontend/vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default defineConfig({
88
},
99
define: {
1010
"import.meta.env.VITE_HTTP_API_URL": JSON.stringify(
11-
"http://13.251.229.198:3000", //"http://localhost:3000",
11+
"https://ckb-tx-elevator-api.ckbapp.dev", //"http://13.251.229.198:3000", //"http://localhost:3000",
1212
),
1313
},
1414
});

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"license": "ISC",
2323
"devDependencies": {
2424
"@biomejs/biome": "^1.9.4",
25+
"@types/cors": "^2.8.17",
2526
"@types/express": "^5.0.0",
2627
"@types/node": "^22.10.2",
2728
"@types/ws": "^8.5.13",
@@ -33,6 +34,7 @@
3334
"@ckb-ccc/core": "^1.2.1",
3435
"@types/better-sqlite3": "^7.6.12",
3536
"better-sqlite3": "^11.7.2",
37+
"cors": "^2.8.5",
3638
"dotenv": "^16.4.7",
3739
"express": "^4.21.2",
3840
"winston": "^3.17.0",

pnpm-lock.yaml

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api/sever.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,18 @@ import express, { type Request, type Response } from "express";
33
import { Config } from "../core/config";
44
import type { DB } from "../db";
55
import { logger } from "../util/logger";
6+
import cors from "cors";
67

78
export function createServer(db: DB) {
89
const app = express();
910

10-
app.use((_req, res, next) => {
11-
for (const origin of Config.allowOrigin) {
12-
res.header("Access-Control-Allow-Origin", origin);
13-
}
14-
if (Config.allowOrigin.length > 0) {
15-
res.header(
16-
"Access-Control-Allow-Methods",
17-
"GET, POST, PUT, DELETE",
18-
);
19-
res.header("Access-Control-Allow-Headers", "Content-Type");
20-
}
21-
22-
next();
23-
});
11+
app.use(
12+
cors({
13+
origin: Config.allowOrigin,
14+
methods: "GET, POST, PUT, DELETE",
15+
allowedHeaders: "Content-Type",
16+
}),
17+
);
2418

2519
app.get("/pending-txs", async (_req: Request, res: Response) => {
2620
const transactions = db.getPendingTransactions();

0 commit comments

Comments
 (0)