add error handler
This commit is contained in:
@@ -17,18 +17,19 @@
|
||||
"esbuild": "^0.14.10",
|
||||
"esno": "^0.13.0",
|
||||
"express": "^4.17.2",
|
||||
"express-promise-router": "^4.1.1",
|
||||
"gray-matter": "^4.0.3",
|
||||
"http-terminator": "^3.0.4",
|
||||
"markdown-it": "^12.3.0",
|
||||
"markdown-it-prism": "^2.2.1",
|
||||
"pino": "^7.6.2",
|
||||
"pino-colada": "^2.2.2",
|
||||
"pino-http": "^6.5.0",
|
||||
"postcss": "^8.4.5",
|
||||
"reacord": "workspace:*",
|
||||
"react": "^18.0.0-rc.0",
|
||||
"react-dom": "^18.0.0-rc.0",
|
||||
"postcss": "^8.4.5",
|
||||
"tailwindcss": "^3.0.8",
|
||||
"markdown-it": "^12.3.0",
|
||||
"markdown-it-prism": "^2.2.1"
|
||||
"tailwindcss": "^3.0.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/browser-sync": "^2.26.3",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import compression from "compression"
|
||||
import type { Request } from "express"
|
||||
import type { ErrorRequestHandler, Request } from "express"
|
||||
import express from "express"
|
||||
import Router from "express-promise-router"
|
||||
import httpTerminator from "http-terminator"
|
||||
import pino from "pino"
|
||||
import pinoHttp from "pino-http"
|
||||
@@ -16,7 +17,12 @@ import { Landing } from "./pages/landing"
|
||||
const logger = pino()
|
||||
const port = process.env.PORT || 3000
|
||||
|
||||
const app = express()
|
||||
const errorHandler: ErrorRequestHandler = (error, request, response, next) => {
|
||||
response.status(500).send(error.message)
|
||||
logger.error(error)
|
||||
}
|
||||
|
||||
const router = Router()
|
||||
.use(pinoHttp({ logger }))
|
||||
.use(compression())
|
||||
.get("/tailwind.css", serveTailwindCss())
|
||||
@@ -51,9 +57,13 @@ const app = express()
|
||||
sendJsx(res, <Landing />)
|
||||
})
|
||||
|
||||
const server = app.listen(port, () => {
|
||||
logger.info(`Server is running on https://localhost:${port}`)
|
||||
})
|
||||
.use(errorHandler)
|
||||
|
||||
const server = express()
|
||||
.use(router)
|
||||
.listen(port, () => {
|
||||
logger.info(`Server is running on https://localhost:${port}`)
|
||||
})
|
||||
|
||||
const terminator = httpTerminator.createHttpTerminator({ server })
|
||||
|
||||
|
||||
27
pnpm-lock.yaml
generated
27
pnpm-lock.yaml
generated
@@ -58,6 +58,7 @@ importers:
|
||||
esno: ^0.13.0
|
||||
execa: ^6.0.0
|
||||
express: ^4.17.2
|
||||
express-promise-router: ^4.1.1
|
||||
fast-glob: ^3.2.7
|
||||
gray-matter: ^4.0.3
|
||||
http-terminator: ^3.0.4
|
||||
@@ -82,6 +83,7 @@ importers:
|
||||
esbuild: 0.14.10
|
||||
esno: 0.13.0_typescript@4.5.4
|
||||
express: 4.17.2
|
||||
express-promise-router: 4.1.1_1b803edea6f06711ee906a90f400b6a4
|
||||
gray-matter: 4.0.3
|
||||
http-terminator: 3.0.4
|
||||
markdown-it: 12.3.0
|
||||
@@ -3560,6 +3562,23 @@ packages:
|
||||
jest-regex-util: 27.4.0
|
||||
dev: true
|
||||
|
||||
/express-promise-router/4.1.1_1b803edea6f06711ee906a90f400b6a4:
|
||||
resolution: {integrity: sha512-Lkvcy/ZGrBhzkl3y7uYBHLMtLI4D6XQ2kiFg9dq7fbktBch5gjqJ0+KovX0cvCAvTJw92raWunRLM/OM+5l4fA==}
|
||||
engines: {node: '>=10'}
|
||||
peerDependencies:
|
||||
'@types/express': ^4.0.0
|
||||
express: ^4.0.0
|
||||
peerDependenciesMeta:
|
||||
'@types/express':
|
||||
optional: true
|
||||
dependencies:
|
||||
'@types/express': 4.17.13
|
||||
express: 4.17.2
|
||||
is-promise: 4.0.0
|
||||
lodash.flattendeep: 4.4.0
|
||||
methods: 1.1.2
|
||||
dev: false
|
||||
|
||||
/express/4.17.2:
|
||||
resolution: {integrity: sha512-oxlxJxcQlYwqPWKVJJtvQiwHgosH/LrLSPA+H4UxpyvSS6jC5aH+5MoHFM+KABgTOt0APue4w66Ha8jCUo9QGg==}
|
||||
engines: {node: '>= 0.10.0'}
|
||||
@@ -4589,6 +4608,10 @@ packages:
|
||||
resolution: {integrity: sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==}
|
||||
dev: true
|
||||
|
||||
/is-promise/4.0.0:
|
||||
resolution: {integrity: sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==}
|
||||
dev: false
|
||||
|
||||
/is-regex/1.1.4:
|
||||
resolution: {integrity: sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==}
|
||||
engines: {node: '>= 0.4'}
|
||||
@@ -5527,6 +5550,10 @@ packages:
|
||||
resolution: {integrity: sha1-wCUTUV4wna3dTCTGDP3c9ZdtkRU=}
|
||||
dev: false
|
||||
|
||||
/lodash.flattendeep/4.4.0:
|
||||
resolution: {integrity: sha1-+wMJF/hqMTTlvJvsDWngAT3f7bI=}
|
||||
dev: false
|
||||
|
||||
/lodash.isfinite/3.3.2:
|
||||
resolution: {integrity: sha1-+4m2WpqAKBgz8LdHizpRBPiY67M=}
|
||||
dev: true
|
||||
|
||||
Reference in New Issue
Block a user