@nitra/fastify 2.2.1 → 2.2.3

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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/index.js +13 -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.1",
4
+ "version": "2.2.3",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
7
7
  "files": [
@@ -24,7 +24,7 @@
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
26
  "@fastify/sensible": "^6.0.3",
27
- "@nitra/pino": "^1.5.0",
28
- "fastify": "^5.2.1"
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('/*', async (req, reply) => {
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')
@@ -42,19 +44,24 @@ app.addHook('preHandler', (req, reply, done) => {
42
44
  * Запускаємо сервер
43
45
  */
44
46
  export function listen() {
47
+ // Якщо ми запущені з нексусом
48
+ // то додаємо в шлях в консолі '/graphql'
49
+ const pluginMeta = app[Symbol.for('registered-plugin')]
50
+ const path = pluginMeta.includes('@nitra/as-integrations-fastify') ? '/graphql' : ''
51
+
45
52
  app
46
53
  .listen({ port, host: '0.0.0.0' })
47
- .then(address => console.log(`🚀 Server ready at ${address}`))
54
+ .then(address => log.info(`🚀 Server ready at ${address + path}`))
48
55
  .catch(error => {
49
- console.error('Error starting server:', error)
56
+ log.error('Error starting server:', error)
50
57
  exit(1)
51
58
  })
52
59
  }
53
60
 
54
61
  /**
55
62
  *
56
- * @param req
57
- * @param reply
63
+ * @param {*} req req
64
+ * @param {*} reply reply
58
65
  */
59
66
  function setHeaders(req, reply) {
60
67
  let host = env.ORIGIN || req.headers.origin || req.headers.referer