Skip to content

Commit

Permalink
fix: properly return value
Browse files Browse the repository at this point in the history
  • Loading branch information
KagChi committed May 10, 2024
1 parent fd72089 commit f60e23c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "The standalone postgres proxy for drizzle.",
"main": "dist",
"scripts": {
"start:dev": "pnpm run build && node dist",
"start:dev": "pnpm run build && node -r dotenv/config dist",
"lint": "eslint src",
"lint:fix": "eslint src --fix",
"build": "rimraf dist && swc src -d dist --strip-leading-paths"
Expand All @@ -20,6 +20,7 @@
"@types/pg": "^8.11.6",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"dotenv": "^16.4.5",
"drizzle-kit": "^0.21.0",
"eslint": "^8.57.0",
"rimraf": "^5.0.5",
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const config = {
migrate: process.env.DATABASE_MIGRATIONS === "true"
},
port: Number(process.env.PORT ?? "3000"),
auth: process.env.AUTH!
auth: process.env.DATABASE_AUTH!
};

if (config.database.migrate) {
Expand Down Expand Up @@ -42,7 +42,10 @@ server.post("/query", async (req, res) => {
const { sql, params, method } = await req.json<RequestBody, RequestBody>();

if (req.headers.authorization !== config.auth) {
res.status(401).json({ error: "Invalid authorization token!" });
res.status(401).json({
error: "Invalid authorization token!"
});
return;
}

logger.info({
Expand All @@ -64,7 +67,7 @@ server.post("/query", async (req, res) => {
} catch (error: any) {
res.status(500).json({ error });
}
res.status(500).json({ error: "Unknown method value" });
res.status(500).json([{ error: "Unknown method value" }]);
});

await server.listen(config.port, "0.0.0.0");
Expand Down

0 comments on commit f60e23c

Please sign in to comment.