refacto: Changing some docker images to hardened non-root ones + README update
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import express from "express";
|
||||
import cors from "cors";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import authRouter from "./routes/auth.js";
|
||||
@@ -8,6 +9,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const publicDir = path.join(__dirname, "..", "public");
|
||||
|
||||
const app = express();
|
||||
app.use(cors({ origin: process.env.CORS_ORIGIN ?? "*" }));
|
||||
app.use(express.json());
|
||||
app.use(express.static(publicDir));
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import pg from "pg";
|
||||
|
||||
const DATABASE_URL =
|
||||
process.env.DATABASE_URL ?? "postgres://game:game@localhost:5432/star_wars_grid";
|
||||
if (!process.env.DATABASE_URL) {
|
||||
throw new Error("[startup] DATABASE_URL environment variable is required but not set.");
|
||||
}
|
||||
if (!process.env.USERS_DATABASE_URL) {
|
||||
throw new Error("[startup] USERS_DATABASE_URL environment variable is required but not set.");
|
||||
}
|
||||
|
||||
const USERS_DATABASE_URL =
|
||||
process.env.USERS_DATABASE_URL ?? "postgres://users:users@localhost:5433/star_wars_users";
|
||||
|
||||
export const pool = new pg.Pool({ connectionString: DATABASE_URL });
|
||||
export const usersPool = new pg.Pool({ connectionString: USERS_DATABASE_URL });
|
||||
export const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL });
|
||||
export const usersPool = new pg.Pool({ connectionString: process.env.USERS_DATABASE_URL });
|
||||
8
server/healthcheck.js
Normal file
8
server/healthcheck.js
Normal file
@@ -0,0 +1,8 @@
|
||||
import http from "http";
|
||||
|
||||
const port = Number(process.env.PORT ?? 8080);
|
||||
http
|
||||
.get(`http://localhost:${port}/api/config`, (res) => {
|
||||
process.exit(res.statusCode === 200 ? 0 : 1);
|
||||
})
|
||||
.on("error", () => process.exit(1));
|
||||
@@ -1,6 +1,10 @@
|
||||
import jwt from "jsonwebtoken";
|
||||
|
||||
export const JWT_SECRET = process.env.JWT_SECRET ?? "dev_secret_change_me";
|
||||
if (!process.env.JWT_SECRET) {
|
||||
throw new Error("[startup] JWT_SECRET environment variable is required but not set.");
|
||||
}
|
||||
|
||||
export const JWT_SECRET = process.env.JWT_SECRET;
|
||||
|
||||
export function authMiddleware(req, res, next) {
|
||||
const authHeader = req.headers["authorization"];
|
||||
|
||||
Reference in New Issue
Block a user