diff --git a/package.json b/package.json index f89c63c..09a4f38 100644 --- a/package.json +++ b/package.json @@ -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" @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a2ca066..da75253 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -48,6 +48,9 @@ importers: '@typescript-eslint/parser': specifier: ^7.8.0 version: 7.8.0(eslint@8.57.0)(typescript@5.4.5) + dotenv: + specifier: ^16.4.5 + version: 16.4.5 drizzle-kit: specifier: ^0.21.0 version: 0.21.0 @@ -995,6 +998,10 @@ packages: resolution: {integrity: sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==} engines: {node: '>=6.0.0'} + dotenv@16.4.5: + resolution: {integrity: sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==} + engines: {node: '>=12'} + dreamopt@0.8.0: resolution: {integrity: sha512-vyJTp8+mC+G+5dfgsY+r3ckxlz+QMX40VjPQsZc5gxVAxLmi64TBoVkP54A/pRAXMXsbu2GMMBrZPxNv23waMg==} engines: {node: '>=0.4.0'} @@ -3495,6 +3502,8 @@ snapshots: dependencies: esutils: 2.0.3 + dotenv@16.4.5: {} + dreamopt@0.8.0: dependencies: wordwrap: 1.0.0 diff --git a/src/index.ts b/src/index.ts index 804e199..7357c1e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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) { @@ -42,7 +42,10 @@ server.post("/query", async (req, res) => { const { sql, params, method } = await req.json(); 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({ @@ -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");