geonix 1.10.10 → 1.10.12

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "geonix",
3
- "version": "1.10.10",
3
+ "version": "1.10.12",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "bin": {
@@ -16,15 +16,15 @@
16
16
  "license": "MIT",
17
17
  "dependencies": {
18
18
  "cookie-parser": "^1.4.6",
19
- "express": "^4.18.2",
19
+ "express": "^4.19.2",
20
20
  "express-async-errors": "^3.1.1",
21
21
  "express-ws": "^5.0.2",
22
22
  "multer": "^1.4.5-lts.1",
23
- "nats": "^2.16.0",
24
- "semver": "^7.5.4",
25
- "ws": "^8.13.0"
23
+ "nats": "^2.26.0",
24
+ "semver": "^7.6.2",
25
+ "ws": "^8.17.0"
26
26
  },
27
27
  "publishConfig": {
28
28
  "registry": "https://registry.npmjs.org/"
29
29
  }
30
- }
30
+ }
package/src/Gateway.js CHANGED
@@ -28,7 +28,8 @@ const stats = {
28
28
  }
29
29
 
30
30
  const defaultOpts = {
31
- afterRequest: (req, res) => { },
31
+ beforeRequest: (req, res) => { },
32
+ afterRequest: (req, res) => { }
32
33
  }
33
34
 
34
35
 
@@ -90,6 +91,13 @@ export class Gateway {
90
91
  if (process.env.NODE_ENV !== 'production')
91
92
  this.#api.use(DEBUG_ENDPOINT, this.#debugRouter())
92
93
 
94
+ this.#api.use((req, res, next) => {
95
+ if (this.#opts.beforeRequest) {
96
+ this.#opts.beforeRequest(req, res)
97
+ }
98
+ next()
99
+ })
100
+
93
101
  // handle mapped endpoints as service calls
94
102
  this.#api.use(raw, (req, res, next) => {
95
103
  stats.requests++
@@ -0,0 +1,15 @@
1
+ import { Gateway, Service } from "../exports.js";
2
+
3
+ class TestService extends Service {
4
+
5
+ 'GET /'(req, res) {
6
+ res.send('Hello World')
7
+ }
8
+ }
9
+
10
+ TestService.start()
11
+ Gateway.start({
12
+ beforeRequest: (req, res) => {
13
+ res.set('X-Test', 'Test')
14
+ }
15
+ })