@nitra/fastify 2.2.0 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/index.js +8 -6
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nitra/fastify",
|
|
3
3
|
"description": "Fastify helper",
|
|
4
|
-
"version": "2.2.
|
|
4
|
+
"version": "2.2.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"files": [
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"homepage": "https://github.com/nitra/fastify",
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@fastify/sensible": "^6.0.
|
|
27
|
-
"@nitra/pino": "^1.
|
|
28
|
-
"fastify": "^5.
|
|
26
|
+
"@fastify/sensible": "^6.0.3",
|
|
27
|
+
"@nitra/pino": "^1.5.1",
|
|
28
|
+
"fastify": "^5.2.2"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/index.js
CHANGED
|
@@ -5,16 +5,18 @@ import { env, exit } from 'node:process'
|
|
|
5
5
|
|
|
6
6
|
const port = Number(env.PORT) || 8080
|
|
7
7
|
|
|
8
|
+
export const log = getLogger()
|
|
9
|
+
|
|
8
10
|
export const app = fastify({
|
|
9
11
|
loggerInstance: getLogger(),
|
|
10
|
-
bodyLimit: (env.BODY_LIMIT_MB || 1) * 1024 * 1024,
|
|
12
|
+
bodyLimit: Number(env.BODY_LIMIT_MB || 1) * 1024 * 1024,
|
|
11
13
|
http2: !!env.K_SERVICE // Запускаємо з http2 якщо в Cloud Run
|
|
12
14
|
})
|
|
13
15
|
|
|
14
16
|
app.register(fastifySensible) // для reply.badRequest(`Not found url: ${req.url} ...`)
|
|
15
17
|
|
|
16
18
|
// Опрацювання запитів OPTIONS
|
|
17
|
-
app.options('/*',
|
|
19
|
+
app.options('/*', (req, reply) => {
|
|
18
20
|
// + setHeaders в preHandler
|
|
19
21
|
reply.header('Access-Control-Max-Age', 86400)
|
|
20
22
|
reply.header('Cache-Control', 'public, max-age=86400')
|
|
@@ -44,17 +46,17 @@ app.addHook('preHandler', (req, reply, done) => {
|
|
|
44
46
|
export function listen() {
|
|
45
47
|
app
|
|
46
48
|
.listen({ port, host: '0.0.0.0' })
|
|
47
|
-
.then(address =>
|
|
49
|
+
.then(address => log.info(`🚀 Server ready at ${address}`))
|
|
48
50
|
.catch(error => {
|
|
49
|
-
|
|
51
|
+
log.error('Error starting server:', error)
|
|
50
52
|
exit(1)
|
|
51
53
|
})
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
/**
|
|
55
57
|
*
|
|
56
|
-
* @param req
|
|
57
|
-
* @param reply
|
|
58
|
+
* @param {*} req req
|
|
59
|
+
* @param {*} reply reply
|
|
58
60
|
*/
|
|
59
61
|
function setHeaders(req, reply) {
|
|
60
62
|
let host = env.ORIGIN || req.headers.origin || req.headers.referer
|