Skip to content

Commit

Permalink
feat(support): connect db
Browse files Browse the repository at this point in the history
  • Loading branch information
seaerchin committed Apr 4, 2024
1 parent b790ae6 commit 32b46cb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,5 +411,5 @@ sequelize

// If we cannot connect to the db, report an error using status code
// And gracefully shut down the application since we can't serve client
process.exitCode = 1
process.exit(1)
})
24 changes: 18 additions & 6 deletions support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "module-alias/register"

import express from "express"

import { infraService } from "@common/index"
import { infraService, sequelize } from "@common/index"
import { useSharedMiddleware } from "@common/middleware"
import { config } from "@root/config/config"
import logger from "@root/logger/logger"
Expand All @@ -18,11 +18,23 @@ infraService.pollMessages()

useSharedMiddleware(app)

// TODO: prefix under infra
// FormSG Backend handler routes
app.use("/", v2Router)
app.use("/v2/ping", (req, res) => res.status(200).send("Ok"))

app.listen(PORT, () => {
logger.info(`Infra container started on port ${PORT}`)
})
sequelize
.authenticate()
.then(() => {
logger.info(
"Connection to db has been established successfully on support service."
)
app.listen(PORT, () => {
logger.info(`Infra container started on port ${PORT}`)
})
})
.catch((err) => {
logger.error(`Unable to connect to the database: ${err}`)

// If we cannot connect to the db, report an error using status code
// And gracefully shut down the application since we can't serve client
process.exit(1)
})

0 comments on commit 32b46cb

Please sign in to comment.