oc-fastify-server-adapter 0.1.0 → 0.1.2
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/dist/index.d.ts +6 -2
- package/dist/index.js +33 -7
- package/package.json +4 -2
package/dist/index.d.ts
CHANGED
|
@@ -100,5 +100,9 @@ export interface FastifyServerAdapterOptions {
|
|
|
100
100
|
port?: number | string;
|
|
101
101
|
trustProxy?: boolean | string | string[] | number;
|
|
102
102
|
}
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
type FastifyServerAdapterFactory = {
|
|
104
|
+
(options?: unknown): HttpServerAdapter;
|
|
105
|
+
readonly __serverAdapterOptions?: FastifyServerAdapterOptions | number | string;
|
|
106
|
+
};
|
|
107
|
+
declare const createFastifyAdapter: FastifyServerAdapterFactory;
|
|
108
|
+
export default createFastifyAdapter;
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.default = createFastifyAdapter;
|
|
7
6
|
const node_fs_1 = require("node:fs");
|
|
8
7
|
const promises_1 = require("node:fs/promises");
|
|
9
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
@@ -21,12 +20,8 @@ const ocResponseSym = Symbol('ocResponse');
|
|
|
21
20
|
const timingStartSym = Symbol('timingStart');
|
|
22
21
|
const multipartParsedSym = Symbol('multipartParsed');
|
|
23
22
|
const defaultBodyLimit = 100 * 1024;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
? options
|
|
27
|
-
: { port: options };
|
|
28
|
-
return new FastifyHttpServerAdapter(adapterOptions);
|
|
29
|
-
}
|
|
23
|
+
const createFastifyAdapter = ((options) => new FastifyHttpServerAdapter(toFastifyAdapterOptions(options)));
|
|
24
|
+
exports.default = createFastifyAdapter;
|
|
30
25
|
class FastifyHttpServerAdapter {
|
|
31
26
|
name = 'fastify';
|
|
32
27
|
app;
|
|
@@ -492,6 +487,36 @@ function normalisePort(port) {
|
|
|
492
487
|
}
|
|
493
488
|
return parsed;
|
|
494
489
|
}
|
|
490
|
+
function toFastifyAdapterOptions(options) {
|
|
491
|
+
if (typeof options === 'undefined' ||
|
|
492
|
+
typeof options === 'number' ||
|
|
493
|
+
typeof options === 'string') {
|
|
494
|
+
return { port: options };
|
|
495
|
+
}
|
|
496
|
+
if (isFastifyAdapterOptions(options)) {
|
|
497
|
+
return options;
|
|
498
|
+
}
|
|
499
|
+
throw new Error('Invalid Fastify server adapter options');
|
|
500
|
+
}
|
|
501
|
+
function isFastifyAdapterOptions(options) {
|
|
502
|
+
if (!options || typeof options !== 'object') {
|
|
503
|
+
return false;
|
|
504
|
+
}
|
|
505
|
+
const candidate = options;
|
|
506
|
+
const port = candidate.port;
|
|
507
|
+
const host = candidate.host;
|
|
508
|
+
const trustProxy = candidate.trustProxy;
|
|
509
|
+
return ((typeof port === 'undefined' ||
|
|
510
|
+
typeof port === 'number' ||
|
|
511
|
+
typeof port === 'string') &&
|
|
512
|
+
(typeof host === 'undefined' || typeof host === 'string') &&
|
|
513
|
+
(typeof trustProxy === 'undefined' ||
|
|
514
|
+
typeof trustProxy === 'boolean' ||
|
|
515
|
+
typeof trustProxy === 'string' ||
|
|
516
|
+
typeof trustProxy === 'number' ||
|
|
517
|
+
(Array.isArray(trustProxy) &&
|
|
518
|
+
trustProxy.every((item) => typeof item === 'string'))));
|
|
519
|
+
}
|
|
495
520
|
function toFastifyRoutePath(routePath) {
|
|
496
521
|
return routePath.replace(/\*[A-Za-z0-9_]+/g, '*');
|
|
497
522
|
}
|
|
@@ -579,3 +604,4 @@ function isResponseSent(res) {
|
|
|
579
604
|
? res.sent
|
|
580
605
|
: res.raw.writableEnded || res.raw.headersSent;
|
|
581
606
|
}
|
|
607
|
+
module.exports = createFastifyAdapter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oc-fastify-server-adapter",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Fastify HTTP server adapter for OC",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -38,7 +38,9 @@
|
|
|
38
38
|
"jest": {
|
|
39
39
|
"preset": "ts-jest",
|
|
40
40
|
"testEnvironment": "node",
|
|
41
|
-
"testPathIgnorePatterns": [
|
|
41
|
+
"testPathIgnorePatterns": [
|
|
42
|
+
"/dist/"
|
|
43
|
+
]
|
|
42
44
|
},
|
|
43
45
|
"dependencies": {
|
|
44
46
|
"@fastify/cookie": "^11.0.2",
|