fastify-txstate 2.3.1 → 2.4.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/lib/index.js +8 -3
  2. package/package.json +2 -8
package/lib/index.js CHANGED
@@ -51,6 +51,8 @@ class Server {
51
51
  await res.status(403).send('Origin check failed. Suspected XSRF attack.');
52
52
  return res;
53
53
  }
54
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
55
+ res.header('Access-Control-Allow-Origin', req.headers.origin);
54
56
  });
55
57
  }
56
58
  this.app.addHook('onSend', async (req, resp, payload) => {
@@ -74,6 +76,9 @@ class Server {
74
76
  else if (err instanceof HttpError) {
75
77
  await res.status(err.statusCode).send(err.message);
76
78
  }
79
+ else if (err.statusCode) {
80
+ await res.status(err.statusCode).send(new HttpError(err.statusCode).message);
81
+ }
77
82
  else {
78
83
  await res.status(500).send('Internal Server Error.');
79
84
  }
@@ -99,7 +104,7 @@ class Server {
99
104
  var _a;
100
105
  const customPort = port !== null && port !== void 0 ? port : parseInt((_a = process.env.PORT) !== null && _a !== void 0 ? _a : '0');
101
106
  if (customPort) {
102
- await this.app.listen(customPort, '::');
107
+ await this.app.listen(customPort, '0.0.0.0');
103
108
  }
104
109
  else if (this.https) {
105
110
  // redirect 80 to 443
@@ -108,10 +113,10 @@ class Server {
108
113
  res.writeHead(301, { Location: 'https://' + ((_c = (_b = (_a = req === null || req === void 0 ? void 0 : req.headers) === null || _a === void 0 ? void 0 : _a.host) === null || _b === void 0 ? void 0 : _b.replace(/:\d+$/, '')) !== null && _c !== void 0 ? _c : '') + ((_d = req.url) !== null && _d !== void 0 ? _d : '') });
109
114
  res.end();
110
115
  }).listen(80);
111
- await this.app.listen(443, '::');
116
+ await this.app.listen(443, '0.0.0.0');
112
117
  }
113
118
  else {
114
- await this.app.listen(80, '::');
119
+ await this.app.listen(80, '0.0.0.0');
115
120
  }
116
121
  }
117
122
  addErrorHandler(handler) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fastify-txstate",
3
- "version": "2.3.1",
3
+ "version": "2.4.0",
4
4
  "description": "A small wrapper for fastify providing a set of common conventions & utility functions we use.",
5
5
  "exports": {
6
6
  "require": "./lib/index.js",
@@ -23,15 +23,9 @@
23
23
  "@types/chai": "^4.2.14",
24
24
  "@types/mocha": "^9.0.0",
25
25
  "@types/node": "^16.7.2",
26
- "@typescript-eslint/eslint-plugin": "^4.5.0",
27
- "@typescript-eslint/parser": "^4.5.0",
28
- "axios": "^0.21.1",
26
+ "axios": ">=0.20.0",
29
27
  "chai": "^4.2.0",
30
- "eslint": "^7.11.0",
31
28
  "eslint-config-standard-with-typescript": "^21.0.1",
32
- "eslint-plugin-import": "^2.22.1",
33
- "eslint-plugin-node": "^11.1.0",
34
- "eslint-plugin-promise": "^5.1.0",
35
29
  "mocha": "^9.1.0",
36
30
  "ts-node": "^10.2.1",
37
31
  "typescript": "^4.4.2"