fastify-txstate 2.4.2 → 3.0.1

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 +15 -14
  2. package/package.json +6 -7
package/lib/index.js CHANGED
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.FailedValidationError = exports.HttpError = void 0;
7
- /* eslint-disable @typescript-eslint/no-floating-promises */
8
7
  const fastify_1 = require("fastify");
9
8
  const fs_1 = __importDefault(require("fs"));
10
9
  const http_1 = __importDefault(require("http"));
@@ -52,21 +51,23 @@ class Server {
52
51
  await res.status(403).send('Origin check failed. Suspected XSRF attack.');
53
52
  return res;
54
53
  }
55
- res.header('Access-Control-Allow-Origin', req.headers.origin);
56
- res.header('Access-Control-Allow-Headers', req.headers['access-control-request-headers']);
54
+ void res.header('Access-Control-Allow-Origin', req.headers.origin);
55
+ if (req.headers['access-control-request-headers'])
56
+ void res.header('Access-Control-Allow-Headers', req.headers['access-control-request-headers']);
57
57
  });
58
58
  this.app.options('*', async (req, res) => {
59
59
  await res.send();
60
60
  });
61
61
  }
62
- this.app.addHook('onSend', async (req, resp, payload) => {
63
- resp.removeHeader('X-Powered-By');
64
- });
65
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
66
- this.app.setNotFoundHandler(async (req, res) => {
67
- await res.status(404).send('Not Found.');
68
- });
69
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
62
+ this.app.addHook('onSend', this.https && process.env.NODE_ENV !== 'development'
63
+ ? async (_, resp) => {
64
+ resp.removeHeader('X-Powered-By');
65
+ void resp.header('Strict-Transport-Security', 'max-age=31536000');
66
+ }
67
+ : async (_, resp) => {
68
+ resp.removeHeader('X-Powered-By');
69
+ });
70
+ this.app.setNotFoundHandler((req, res) => { void res.status(404).send('Not Found.'); });
70
71
  this.app.setErrorHandler(async (err, req, res) => {
71
72
  req.log.warn(err);
72
73
  for (const errorHandler of this.errorHandlers) {
@@ -108,7 +109,7 @@ class Server {
108
109
  var _a;
109
110
  const customPort = port !== null && port !== void 0 ? port : parseInt((_a = process.env.PORT) !== null && _a !== void 0 ? _a : '0');
110
111
  if (customPort) {
111
- await this.app.listen(customPort, '0.0.0.0');
112
+ await this.app.listen({ port: customPort, host: '0.0.0.0' });
112
113
  }
113
114
  else if (this.https) {
114
115
  // redirect 80 to 443
@@ -117,10 +118,10 @@ class Server {
117
118
  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 : '') });
118
119
  res.end();
119
120
  }).listen(80);
120
- await this.app.listen(443, '0.0.0.0');
121
+ await this.app.listen({ port: 443, host: '0.0.0.0' });
121
122
  }
122
123
  else {
123
- await this.app.listen(80, '0.0.0.0');
124
+ await this.app.listen({ port: 80, host: '0.0.0.0' });
124
125
  }
125
126
  }
126
127
  addErrorHandler(handler) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fastify-txstate",
3
- "version": "2.4.2",
3
+ "version": "3.0.1",
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",
@@ -15,18 +15,17 @@
15
15
  "testserver": "ts-node-script testserver/index.ts"
16
16
  },
17
17
  "dependencies": {
18
- "fastify": "^3.7.0",
19
- "http-status-codes": "^2.1.4",
20
- "pino-pretty": "^7.0.1"
18
+ "fastify": "^4.5.3",
19
+ "http-status-codes": "^2.1.4"
21
20
  },
22
21
  "devDependencies": {
23
22
  "@types/chai": "^4.2.14",
24
- "@types/mocha": "^9.0.0",
23
+ "@types/mocha": "^9.1.1",
25
24
  "@types/node": "^16.7.2",
26
25
  "axios": ">=0.20.0",
27
26
  "chai": "^4.2.0",
28
- "eslint-config-standard-with-typescript": "^21.0.1",
29
- "mocha": "^9.1.0",
27
+ "eslint-config-standard-with-typescript": "^22.0.0",
28
+ "mocha": "^10.0.0",
30
29
  "ts-node": "^10.2.1",
31
30
  "typescript": "^4.4.2"
32
31
  },