@nitra/fastify 1.5.2 → 1.6.0

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 +6 -2
  2. package/src/pubsub.js +27 -0
package/package.json CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "@nitra/fastify",
3
3
  "description": "Fastify helper",
4
- "version": "1.5.2",
4
+ "version": "1.6.0",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
7
7
  "files": [
8
8
  "src"
9
9
  ],
10
+ "exports": {
11
+ ".": "./src/index.js",
12
+ "./pubsub": "./src/pubsub.js"
13
+ },
10
14
  "keywords": [
11
15
  "nitra",
12
16
  "fastify"
@@ -20,7 +24,7 @@
20
24
  "license": "MIT",
21
25
  "dependencies": {
22
26
  "@fastify/sensible": "^5.1.1",
23
- "@nitra/bunyan": "^1.1.5",
27
+ "@nitra/bunyan": "^2.0.0",
24
28
  "fastify": "^4.9.2"
25
29
  }
26
30
  }
package/src/pubsub.js ADDED
@@ -0,0 +1,27 @@
1
+ import fastify from 'fastify'
2
+ import getLogger from '@nitra/bunyan/trace'
3
+ import { exit, env } from 'node:process'
4
+
5
+ const port = Number(env.PORT) || 8080
6
+
7
+ export const app = fastify({
8
+ http2: !!env.K_SERVICE // Запускаємо з http2 якщо в Cloud Run
9
+ })
10
+
11
+ app.addHook('preHandler', (req, _, done) => {
12
+ req.log = getLogger(req)
13
+ req.log.info('req.url: ', req.url)
14
+
15
+ done()
16
+ })
17
+
18
+ // Запускаємо сервер
19
+ export function listen() {
20
+ app
21
+ .listen({ port, host: '0.0.0.0' })
22
+ .then(address => console.log(`🚀 PubSub Consumer ready at ${address}`))
23
+ .catch(err => {
24
+ console.error('Error starting server:', err)
25
+ exit(1)
26
+ })
27
+ }