Skip to content

Commit

Permalink
Clean up express app startup and add debug info to server startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Francis Duvivier committed Jan 28, 2025
1 parent aa89e37 commit 3fb7300
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
14 changes: 0 additions & 14 deletions src/app.ts

This file was deleted.

17 changes: 15 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import app from "./app";
import { RegisterRoutes } from "./generated/routes";
import { addTsoaValidationFailureLogging } from "@util/logging";
import { EXPRESS_PORT, NODE_ENV } from "@config";
import { disableWriteWhenNotDev } from "@disableWriteWhenNotDev";
import { runMigrations } from "@db/migrations";
import setupPopulateDBApi from "./setupPopulateDBApi";
import express from "express";
import openapi from "./openapi";
import { pinoHttp } from "pino-http";

async function startServer() {
const app = express();
const pino = pinoHttp();

app.use(express.json());
app.use(express.static("public"));
app.use(pino);

openapi(app);

disableWriteWhenNotDev(app);

if (NODE_ENV === "development") {
Expand All @@ -19,7 +30,9 @@ async function startServer() {

await runMigrations();
app.listen(EXPRESS_PORT, () => {
console.info(`Node.js server started.`);
console.info(
`Node.js server started. Listening on port ${EXPRESS_PORT}, environment: ${NODE_ENV}`
);
});
}

Expand Down
8 changes: 3 additions & 5 deletions src/setupPopulateDBApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ const badgeSlugs = BADGES.map(nameToSlug); // Hardcoded! Update by hand
const CATEGORIES_COUNT = CATEGORY_NAMES.length;
export default function setupPopulateDBApi(app: Express) {
const router = Router();
// router.use(express.static("public"));

app.use(express.json());
app.use(express.static("public"));
app.use("/", router);
app.use("/populate", router);

const pool = new pg.Pool({
host: POSTGRES_HOST,
Expand All @@ -57,8 +56,7 @@ export default function setupPopulateDBApi(app: Express) {
password: POSTGRES_PASSWORD,
port: POSTGRES_PORT,
});

router.post("/populate", async (req, res) => {
router.post("", async (req, res) => {
const client: pg.PoolClient = await pool.connect();
const badgeHubData = new BadgeHubData(
new PostgreSQLBadgeHubMetadata(),
Expand Down

0 comments on commit 3fb7300

Please sign in to comment.