@forklaunch/hyper-express 0.2.0 → 0.2.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/lib/index.d.mts +95 -0
- package/lib/index.d.ts +95 -0
- package/lib/{hyperExpressApplication.js → index.js} +124 -8
- package/lib/index.mjs +230 -0
- package/package.json +24 -24
- package/lib/hyperExpressApplication.d.mts +0 -30
- package/lib/hyperExpressApplication.d.ts +0 -30
- package/lib/hyperExpressApplication.mjs +0 -111
- package/lib/hyperExpressRouter.d.mts +0 -12
- package/lib/hyperExpressRouter.d.ts +0 -12
- package/lib/hyperExpressRouter.js +0 -130
- package/lib/hyperExpressRouter.mjs +0 -109
- package/lib/middleware/contentParse.middleware.d.mts +0 -10
- package/lib/middleware/contentParse.middleware.d.ts +0 -10
- package/lib/middleware/contentParse.middleware.js +0 -49
- package/lib/middleware/contentParse.middleware.mjs +0 -24
- package/lib/middleware/enrichResponseTransmission.middleware.d.mts +0 -17
- package/lib/middleware/enrichResponseTransmission.middleware.d.ts +0 -17
- package/lib/middleware/enrichResponseTransmission.middleware.js +0 -67
- package/lib/middleware/enrichResponseTransmission.middleware.mjs +0 -44
- package/lib/middleware/polyfillGetHeaders.middleware.d.mts +0 -5
- package/lib/middleware/polyfillGetHeaders.middleware.d.ts +0 -5
- package/lib/middleware/polyfillGetHeaders.middleware.js +0 -36
- package/lib/middleware/polyfillGetHeaders.middleware.mjs +0 -11
- package/lib/middleware/swagger.middleware.d.mts +0 -27
- package/lib/middleware/swagger.middleware.d.ts +0 -27
- package/lib/middleware/swagger.middleware.js +0 -97
- package/lib/middleware/swagger.middleware.mjs +0 -61
- package/lib/types/hyperExpress.types.d.mts +0 -44
- package/lib/types/hyperExpress.types.d.ts +0 -44
- package/lib/types/hyperExpress.types.js +0 -18
- package/lib/types/hyperExpress.types.mjs +0 -0
@@ -1,30 +0,0 @@
|
|
1
|
-
import { ForklaunchExpressLikeApplication } from '@forklaunch/core/http';
|
2
|
-
import { AnySchemaValidator } from '@forklaunch/validator';
|
3
|
-
import { Server, MiddlewareHandler } from 'hyper-express';
|
4
|
-
import * as uWebsockets from 'uWebSockets.js';
|
5
|
-
|
6
|
-
/**
|
7
|
-
* Represents an application built on top of Hyper-Express and Forklaunch.
|
8
|
-
*
|
9
|
-
* @template SV - A type that extends AnySchemaValidator.
|
10
|
-
*/
|
11
|
-
declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpressLikeApplication<SV, Server, MiddlewareHandler> {
|
12
|
-
/**
|
13
|
-
* Creates an instance of the Application class.
|
14
|
-
*
|
15
|
-
* @param {SV} schemaValidator - The schema validator.
|
16
|
-
*/
|
17
|
-
constructor(schemaValidator: SV);
|
18
|
-
/**
|
19
|
-
* Starts the server and sets up Swagger documentation.
|
20
|
-
*
|
21
|
-
* @param {string | number} arg0 - The port number or UNIX path to listen on.
|
22
|
-
* @param {...unknown[]} args - Additional arguments.
|
23
|
-
* @returns {Promise<uWebsockets.us_listen_socket>} - A promise that resolves with the listening socket.
|
24
|
-
*/
|
25
|
-
listen(port: number, callback?: (listen_socket: uWebsockets.us_listen_socket) => void): Promise<uWebsockets.us_listen_socket>;
|
26
|
-
listen(port: number, host?: string, callback?: (listen_socket: uWebsockets.us_listen_socket) => void): Promise<uWebsockets.us_listen_socket>;
|
27
|
-
listen(unix_path: string, callback?: (listen_socket: uWebsockets.us_listen_socket) => void): Promise<uWebsockets.us_listen_socket>;
|
28
|
-
}
|
29
|
-
|
30
|
-
export { Application };
|
@@ -1,111 +0,0 @@
|
|
1
|
-
// src/hyperExpressApplication.ts
|
2
|
-
import {
|
3
|
-
ForklaunchExpressLikeApplication,
|
4
|
-
generateSwaggerDocument
|
5
|
-
} from "@forklaunch/core/http";
|
6
|
-
import { Server } from "hyper-express";
|
7
|
-
|
8
|
-
// src/middleware/swagger.middleware.ts
|
9
|
-
import LiveDirectory from "live-directory";
|
10
|
-
import getAbsoluteSwaggerFsPath from "swagger-ui-dist/absolute-path";
|
11
|
-
import swaggerUi from "swagger-ui-express";
|
12
|
-
function swaggerRedirect(path) {
|
13
|
-
return (req, res, next) => {
|
14
|
-
if (req.path === path) {
|
15
|
-
res.redirect(`${path}/`);
|
16
|
-
}
|
17
|
-
return next?.();
|
18
|
-
};
|
19
|
-
}
|
20
|
-
function swagger(path, document, opts, options, customCss, customfavIcon, swaggerUrl, customSiteTitle) {
|
21
|
-
const LiveAssets = new LiveDirectory(getAbsoluteSwaggerFsPath(), {
|
22
|
-
filter: {
|
23
|
-
keep: {
|
24
|
-
names: [
|
25
|
-
"swagger-ui-bundle.js",
|
26
|
-
"swagger-ui-standalone-preset.js",
|
27
|
-
"swagger-ui-init.js",
|
28
|
-
"swagger-ui.css",
|
29
|
-
"favicon-32x32.png",
|
30
|
-
"favicon-16x16.png"
|
31
|
-
]
|
32
|
-
}
|
33
|
-
},
|
34
|
-
cache: {
|
35
|
-
max_file_count: 10,
|
36
|
-
max_file_size: 1024 * 1024 * 1.5
|
37
|
-
}
|
38
|
-
});
|
39
|
-
const serve = swaggerUi.serve[0];
|
40
|
-
const staticAssets = (req, res, next) => {
|
41
|
-
const filePath = req.path.replace(path, "");
|
42
|
-
const file = LiveAssets.get(filePath);
|
43
|
-
if (file === void 0) {
|
44
|
-
if (next) {
|
45
|
-
return next();
|
46
|
-
}
|
47
|
-
return res.status(404).send();
|
48
|
-
}
|
49
|
-
const fileParts = file.path.split(".");
|
50
|
-
const extension = fileParts[fileParts.length - 1];
|
51
|
-
const content = file.content;
|
52
|
-
return res.type(extension).send(content);
|
53
|
-
};
|
54
|
-
const ui = swaggerUi.setup(
|
55
|
-
document,
|
56
|
-
opts,
|
57
|
-
options,
|
58
|
-
customCss,
|
59
|
-
customfavIcon,
|
60
|
-
swaggerUrl,
|
61
|
-
customSiteTitle
|
62
|
-
);
|
63
|
-
return [serve, staticAssets, ui];
|
64
|
-
}
|
65
|
-
|
66
|
-
// src/hyperExpressApplication.ts
|
67
|
-
var Application = class extends ForklaunchExpressLikeApplication {
|
68
|
-
/**
|
69
|
-
* Creates an instance of the Application class.
|
70
|
-
*
|
71
|
-
* @param {SV} schemaValidator - The schema validator.
|
72
|
-
*/
|
73
|
-
constructor(schemaValidator) {
|
74
|
-
super(schemaValidator, new Server());
|
75
|
-
}
|
76
|
-
listen(arg0, arg1, arg2) {
|
77
|
-
if (typeof arg0 === "number") {
|
78
|
-
const port = arg0 || Number(process.env.PORT);
|
79
|
-
this.internal.set_error_handler((_req, res, err) => {
|
80
|
-
res.locals.errorMessage = err.message;
|
81
|
-
console.error(err);
|
82
|
-
res.status(
|
83
|
-
res.statusCode && res.statusCode >= 400 ? res.statusCode : 500
|
84
|
-
).send(`Internal server error:
|
85
|
-
|
86
|
-
${err.message}`);
|
87
|
-
});
|
88
|
-
const swaggerPath = `/api${process.env.VERSION ?? "/v1"}${process.env.SWAGGER_PATH ?? "/swagger"}`;
|
89
|
-
this.internal.use(swaggerPath, swaggerRedirect(swaggerPath));
|
90
|
-
this.internal.get(
|
91
|
-
`${swaggerPath}/*`,
|
92
|
-
swagger(
|
93
|
-
swaggerPath,
|
94
|
-
generateSwaggerDocument(this.schemaValidator, port, this.routers)
|
95
|
-
)
|
96
|
-
);
|
97
|
-
if (arg1 && typeof arg1 === "string") {
|
98
|
-
return this.internal.listen(port, arg1, arg2);
|
99
|
-
} else if (arg1 && typeof arg1 === "function") {
|
100
|
-
return this.internal.listen(port, arg1);
|
101
|
-
}
|
102
|
-
}
|
103
|
-
return this.internal.listen(
|
104
|
-
arg0,
|
105
|
-
arg1
|
106
|
-
);
|
107
|
-
}
|
108
|
-
};
|
109
|
-
export {
|
110
|
-
Application
|
111
|
-
};
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import { ForklaunchExpressLikeRouter, ForklaunchRouter, TypedMiddlewareDefinition } from '@forklaunch/core/http';
|
2
|
-
import { AnySchemaValidator } from '@forklaunch/validator';
|
3
|
-
import { MiddlewareHandler, Router as Router$1 } from 'hyper-express';
|
4
|
-
|
5
|
-
declare class Router<SV extends AnySchemaValidator, BasePath extends `/${string}`> extends ForklaunchExpressLikeRouter<SV, BasePath, MiddlewareHandler, Router$1> implements ForklaunchRouter<SV> {
|
6
|
-
basePath: BasePath;
|
7
|
-
constructor(basePath: BasePath, schemaValidator: SV);
|
8
|
-
route(path: string): this;
|
9
|
-
any: TypedMiddlewareDefinition<this, SV>;
|
10
|
-
}
|
11
|
-
|
12
|
-
export { Router };
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import { ForklaunchExpressLikeRouter, ForklaunchRouter, TypedMiddlewareDefinition } from '@forklaunch/core/http';
|
2
|
-
import { AnySchemaValidator } from '@forklaunch/validator';
|
3
|
-
import { MiddlewareHandler, Router as Router$1 } from 'hyper-express';
|
4
|
-
|
5
|
-
declare class Router<SV extends AnySchemaValidator, BasePath extends `/${string}`> extends ForklaunchExpressLikeRouter<SV, BasePath, MiddlewareHandler, Router$1> implements ForklaunchRouter<SV> {
|
6
|
-
basePath: BasePath;
|
7
|
-
constructor(basePath: BasePath, schemaValidator: SV);
|
8
|
-
route(path: string): this;
|
9
|
-
any: TypedMiddlewareDefinition<this, SV>;
|
10
|
-
}
|
11
|
-
|
12
|
-
export { Router };
|
@@ -1,130 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __defProp = Object.defineProperty;
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __export = (target, all) => {
|
7
|
-
for (var name in all)
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
-
};
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
-
for (let key of __getOwnPropNames(from))
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
-
}
|
16
|
-
return to;
|
17
|
-
};
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
-
|
20
|
-
// src/hyperExpressRouter.ts
|
21
|
-
var hyperExpressRouter_exports = {};
|
22
|
-
__export(hyperExpressRouter_exports, {
|
23
|
-
Router: () => Router
|
24
|
-
});
|
25
|
-
module.exports = __toCommonJS(hyperExpressRouter_exports);
|
26
|
-
var import_http2 = require("@forklaunch/core/http");
|
27
|
-
var import_hyper_express = require("hyper-express");
|
28
|
-
|
29
|
-
// src/middleware/contentParse.middleware.ts
|
30
|
-
async function contentParse(req) {
|
31
|
-
console.debug("[MIDDLEWARE] contentParse started");
|
32
|
-
switch (req.headers["content-type"] && req.headers["content-type"].split(";")[0]) {
|
33
|
-
case "application/json":
|
34
|
-
req.body = await req.json();
|
35
|
-
break;
|
36
|
-
case "application/x-www-form-urlencoded":
|
37
|
-
req.body = await req.urlencoded();
|
38
|
-
break;
|
39
|
-
case "text/plain":
|
40
|
-
req.body = await req.text();
|
41
|
-
break;
|
42
|
-
case "application/octet-stream":
|
43
|
-
req.body = await req.buffer();
|
44
|
-
break;
|
45
|
-
default:
|
46
|
-
req.body = await req.json();
|
47
|
-
break;
|
48
|
-
}
|
49
|
-
}
|
50
|
-
|
51
|
-
// src/middleware/enrichResponseTransmission.middleware.ts
|
52
|
-
var import_http = require("@forklaunch/core/http");
|
53
|
-
function enrichResponseTransmission(req, res, next) {
|
54
|
-
console.debug("[MIDDLEWARE] enrichResponseTransmission");
|
55
|
-
const originalSend = res.send;
|
56
|
-
const originalJson = res.json;
|
57
|
-
const originalSetHeader = res.setHeader;
|
58
|
-
res.json = function(data) {
|
59
|
-
res.bodyData = data;
|
60
|
-
const result = originalJson.call(this, data);
|
61
|
-
return result;
|
62
|
-
};
|
63
|
-
res.send = function(data) {
|
64
|
-
if (!res.bodyData) {
|
65
|
-
res.bodyData = data;
|
66
|
-
res.statusCode = res._status_code;
|
67
|
-
}
|
68
|
-
return (0, import_http.enrichExpressLikeSend)(
|
69
|
-
this,
|
70
|
-
req,
|
71
|
-
res,
|
72
|
-
originalSend,
|
73
|
-
data,
|
74
|
-
!res.cors && (res._cork && !res._corked || !res._cork)
|
75
|
-
);
|
76
|
-
};
|
77
|
-
res.setHeader = function(name, value) {
|
78
|
-
let stringifiedValue;
|
79
|
-
if (Array.isArray(value)) {
|
80
|
-
stringifiedValue = value.map(
|
81
|
-
(v) => typeof v !== "string" ? JSON.stringify(v) : v
|
82
|
-
);
|
83
|
-
} else {
|
84
|
-
stringifiedValue = typeof value !== "string" ? JSON.stringify(value) : value;
|
85
|
-
}
|
86
|
-
return originalSetHeader.call(this, name, stringifiedValue);
|
87
|
-
};
|
88
|
-
next();
|
89
|
-
}
|
90
|
-
|
91
|
-
// src/middleware/polyfillGetHeaders.middleware.ts
|
92
|
-
function polyfillGetHeaders(_req, res, next) {
|
93
|
-
console.debug("[MIDDLEWARE] polyfillGetHeaders started");
|
94
|
-
res.getHeaders = () => {
|
95
|
-
return res._headers;
|
96
|
-
};
|
97
|
-
next?.();
|
98
|
-
}
|
99
|
-
|
100
|
-
// src/hyperExpressRouter.ts
|
101
|
-
var Router = class extends import_http2.ForklaunchExpressLikeRouter {
|
102
|
-
constructor(basePath, schemaValidator) {
|
103
|
-
super(basePath, schemaValidator, new import_hyper_express.Router());
|
104
|
-
this.basePath = basePath;
|
105
|
-
this.internal.use(polyfillGetHeaders);
|
106
|
-
this.internal.use(contentParse);
|
107
|
-
this.internal.use(
|
108
|
-
enrichResponseTransmission
|
109
|
-
);
|
110
|
-
}
|
111
|
-
route(path) {
|
112
|
-
this.internal.route(path);
|
113
|
-
return this;
|
114
|
-
}
|
115
|
-
any = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
|
116
|
-
return this.registerMiddlewareHandler(
|
117
|
-
this.internal.any,
|
118
|
-
pathOrContractDetailsOrMiddlewareOrTypedHandler,
|
119
|
-
contractDetailsOrMiddlewareOrTypedHandler,
|
120
|
-
...middlewareOrMiddlewareWithTypedHandler
|
121
|
-
);
|
122
|
-
};
|
123
|
-
// TODO: Implement the rest of the methods
|
124
|
-
// upgrade
|
125
|
-
// ws
|
126
|
-
};
|
127
|
-
// Annotate the CommonJS export names for ESM import in node:
|
128
|
-
0 && (module.exports = {
|
129
|
-
Router
|
130
|
-
});
|
@@ -1,109 +0,0 @@
|
|
1
|
-
// src/hyperExpressRouter.ts
|
2
|
-
import {
|
3
|
-
ForklaunchExpressLikeRouter
|
4
|
-
} from "@forklaunch/core/http";
|
5
|
-
import { Router as ExpressRouter } from "hyper-express";
|
6
|
-
|
7
|
-
// src/middleware/contentParse.middleware.ts
|
8
|
-
async function contentParse(req) {
|
9
|
-
console.debug("[MIDDLEWARE] contentParse started");
|
10
|
-
switch (req.headers["content-type"] && req.headers["content-type"].split(";")[0]) {
|
11
|
-
case "application/json":
|
12
|
-
req.body = await req.json();
|
13
|
-
break;
|
14
|
-
case "application/x-www-form-urlencoded":
|
15
|
-
req.body = await req.urlencoded();
|
16
|
-
break;
|
17
|
-
case "text/plain":
|
18
|
-
req.body = await req.text();
|
19
|
-
break;
|
20
|
-
case "application/octet-stream":
|
21
|
-
req.body = await req.buffer();
|
22
|
-
break;
|
23
|
-
default:
|
24
|
-
req.body = await req.json();
|
25
|
-
break;
|
26
|
-
}
|
27
|
-
}
|
28
|
-
|
29
|
-
// src/middleware/enrichResponseTransmission.middleware.ts
|
30
|
-
import {
|
31
|
-
enrichExpressLikeSend
|
32
|
-
} from "@forklaunch/core/http";
|
33
|
-
function enrichResponseTransmission(req, res, next) {
|
34
|
-
console.debug("[MIDDLEWARE] enrichResponseTransmission");
|
35
|
-
const originalSend = res.send;
|
36
|
-
const originalJson = res.json;
|
37
|
-
const originalSetHeader = res.setHeader;
|
38
|
-
res.json = function(data) {
|
39
|
-
res.bodyData = data;
|
40
|
-
const result = originalJson.call(this, data);
|
41
|
-
return result;
|
42
|
-
};
|
43
|
-
res.send = function(data) {
|
44
|
-
if (!res.bodyData) {
|
45
|
-
res.bodyData = data;
|
46
|
-
res.statusCode = res._status_code;
|
47
|
-
}
|
48
|
-
return enrichExpressLikeSend(
|
49
|
-
this,
|
50
|
-
req,
|
51
|
-
res,
|
52
|
-
originalSend,
|
53
|
-
data,
|
54
|
-
!res.cors && (res._cork && !res._corked || !res._cork)
|
55
|
-
);
|
56
|
-
};
|
57
|
-
res.setHeader = function(name, value) {
|
58
|
-
let stringifiedValue;
|
59
|
-
if (Array.isArray(value)) {
|
60
|
-
stringifiedValue = value.map(
|
61
|
-
(v) => typeof v !== "string" ? JSON.stringify(v) : v
|
62
|
-
);
|
63
|
-
} else {
|
64
|
-
stringifiedValue = typeof value !== "string" ? JSON.stringify(value) : value;
|
65
|
-
}
|
66
|
-
return originalSetHeader.call(this, name, stringifiedValue);
|
67
|
-
};
|
68
|
-
next();
|
69
|
-
}
|
70
|
-
|
71
|
-
// src/middleware/polyfillGetHeaders.middleware.ts
|
72
|
-
function polyfillGetHeaders(_req, res, next) {
|
73
|
-
console.debug("[MIDDLEWARE] polyfillGetHeaders started");
|
74
|
-
res.getHeaders = () => {
|
75
|
-
return res._headers;
|
76
|
-
};
|
77
|
-
next?.();
|
78
|
-
}
|
79
|
-
|
80
|
-
// src/hyperExpressRouter.ts
|
81
|
-
var Router = class extends ForklaunchExpressLikeRouter {
|
82
|
-
constructor(basePath, schemaValidator) {
|
83
|
-
super(basePath, schemaValidator, new ExpressRouter());
|
84
|
-
this.basePath = basePath;
|
85
|
-
this.internal.use(polyfillGetHeaders);
|
86
|
-
this.internal.use(contentParse);
|
87
|
-
this.internal.use(
|
88
|
-
enrichResponseTransmission
|
89
|
-
);
|
90
|
-
}
|
91
|
-
route(path) {
|
92
|
-
this.internal.route(path);
|
93
|
-
return this;
|
94
|
-
}
|
95
|
-
any = (pathOrContractDetailsOrMiddlewareOrTypedHandler, contractDetailsOrMiddlewareOrTypedHandler, ...middlewareOrMiddlewareWithTypedHandler) => {
|
96
|
-
return this.registerMiddlewareHandler(
|
97
|
-
this.internal.any,
|
98
|
-
pathOrContractDetailsOrMiddlewareOrTypedHandler,
|
99
|
-
contractDetailsOrMiddlewareOrTypedHandler,
|
100
|
-
...middlewareOrMiddlewareWithTypedHandler
|
101
|
-
);
|
102
|
-
};
|
103
|
-
// TODO: Implement the rest of the methods
|
104
|
-
// upgrade
|
105
|
-
// ws
|
106
|
-
};
|
107
|
-
export {
|
108
|
-
Router
|
109
|
-
};
|
@@ -1,10 +0,0 @@
|
|
1
|
-
import { Request } from 'hyper-express';
|
2
|
-
|
3
|
-
/**
|
4
|
-
* Middleware function to parse the request body based on the content type.
|
5
|
-
*
|
6
|
-
* @returns {Function} - The middleware function.
|
7
|
-
*/
|
8
|
-
declare function contentParse(req: Request): Promise<void>;
|
9
|
-
|
10
|
-
export { contentParse };
|
@@ -1,10 +0,0 @@
|
|
1
|
-
import { Request } from 'hyper-express';
|
2
|
-
|
3
|
-
/**
|
4
|
-
* Middleware function to parse the request body based on the content type.
|
5
|
-
*
|
6
|
-
* @returns {Function} - The middleware function.
|
7
|
-
*/
|
8
|
-
declare function contentParse(req: Request): Promise<void>;
|
9
|
-
|
10
|
-
export { contentParse };
|
@@ -1,49 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __defProp = Object.defineProperty;
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __export = (target, all) => {
|
7
|
-
for (var name in all)
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
-
};
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
-
for (let key of __getOwnPropNames(from))
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
-
}
|
16
|
-
return to;
|
17
|
-
};
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
-
|
20
|
-
// src/middleware/contentParse.middleware.ts
|
21
|
-
var contentParse_middleware_exports = {};
|
22
|
-
__export(contentParse_middleware_exports, {
|
23
|
-
contentParse: () => contentParse
|
24
|
-
});
|
25
|
-
module.exports = __toCommonJS(contentParse_middleware_exports);
|
26
|
-
async function contentParse(req) {
|
27
|
-
console.debug("[MIDDLEWARE] contentParse started");
|
28
|
-
switch (req.headers["content-type"] && req.headers["content-type"].split(";")[0]) {
|
29
|
-
case "application/json":
|
30
|
-
req.body = await req.json();
|
31
|
-
break;
|
32
|
-
case "application/x-www-form-urlencoded":
|
33
|
-
req.body = await req.urlencoded();
|
34
|
-
break;
|
35
|
-
case "text/plain":
|
36
|
-
req.body = await req.text();
|
37
|
-
break;
|
38
|
-
case "application/octet-stream":
|
39
|
-
req.body = await req.buffer();
|
40
|
-
break;
|
41
|
-
default:
|
42
|
-
req.body = await req.json();
|
43
|
-
break;
|
44
|
-
}
|
45
|
-
}
|
46
|
-
// Annotate the CommonJS export names for ESM import in node:
|
47
|
-
0 && (module.exports = {
|
48
|
-
contentParse
|
49
|
-
});
|
@@ -1,24 +0,0 @@
|
|
1
|
-
// src/middleware/contentParse.middleware.ts
|
2
|
-
async function contentParse(req) {
|
3
|
-
console.debug("[MIDDLEWARE] contentParse started");
|
4
|
-
switch (req.headers["content-type"] && req.headers["content-type"].split(";")[0]) {
|
5
|
-
case "application/json":
|
6
|
-
req.body = await req.json();
|
7
|
-
break;
|
8
|
-
case "application/x-www-form-urlencoded":
|
9
|
-
req.body = await req.urlencoded();
|
10
|
-
break;
|
11
|
-
case "text/plain":
|
12
|
-
req.body = await req.text();
|
13
|
-
break;
|
14
|
-
case "application/octet-stream":
|
15
|
-
req.body = await req.buffer();
|
16
|
-
break;
|
17
|
-
default:
|
18
|
-
req.body = await req.json();
|
19
|
-
break;
|
20
|
-
}
|
21
|
-
}
|
22
|
-
export {
|
23
|
-
contentParse
|
24
|
-
};
|
@@ -1,17 +0,0 @@
|
|
1
|
-
import { ParamsDictionary, ForklaunchNextFunction } from '@forklaunch/core/http';
|
2
|
-
import { AnySchemaValidator } from '@forklaunch/validator';
|
3
|
-
import { ParsedQs } from 'qs';
|
4
|
-
import { Request, Response } from '../types/hyperExpress.types.mjs';
|
5
|
-
import 'hyper-express';
|
6
|
-
|
7
|
-
/**
|
8
|
-
* Middleware to enrich the response transmission by intercepting and parsing responses before they are sent.
|
9
|
-
*
|
10
|
-
* @template SV - A type that extends AnySchemaValidator.
|
11
|
-
* @param {Request<SV>} req - The request object.
|
12
|
-
* @param {Response} res - The response object.
|
13
|
-
* @param {MiddlewareNext} next - The next middleware function.
|
14
|
-
*/
|
15
|
-
declare function enrichResponseTransmission<SV extends AnySchemaValidator>(req: Request<SV, ParamsDictionary, Record<string, unknown>, ParsedQs, Record<string, string>, Record<string, unknown>>, res: Response<Record<number, unknown>, Record<string, string>, Record<string, unknown>>, next: ForklaunchNextFunction): void;
|
16
|
-
|
17
|
-
export { enrichResponseTransmission };
|
@@ -1,17 +0,0 @@
|
|
1
|
-
import { ParamsDictionary, ForklaunchNextFunction } from '@forklaunch/core/http';
|
2
|
-
import { AnySchemaValidator } from '@forklaunch/validator';
|
3
|
-
import { ParsedQs } from 'qs';
|
4
|
-
import { Request, Response } from '../types/hyperExpress.types.js';
|
5
|
-
import 'hyper-express';
|
6
|
-
|
7
|
-
/**
|
8
|
-
* Middleware to enrich the response transmission by intercepting and parsing responses before they are sent.
|
9
|
-
*
|
10
|
-
* @template SV - A type that extends AnySchemaValidator.
|
11
|
-
* @param {Request<SV>} req - The request object.
|
12
|
-
* @param {Response} res - The response object.
|
13
|
-
* @param {MiddlewareNext} next - The next middleware function.
|
14
|
-
*/
|
15
|
-
declare function enrichResponseTransmission<SV extends AnySchemaValidator>(req: Request<SV, ParamsDictionary, Record<string, unknown>, ParsedQs, Record<string, string>, Record<string, unknown>>, res: Response<Record<number, unknown>, Record<string, string>, Record<string, unknown>>, next: ForklaunchNextFunction): void;
|
16
|
-
|
17
|
-
export { enrichResponseTransmission };
|
@@ -1,67 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __defProp = Object.defineProperty;
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __export = (target, all) => {
|
7
|
-
for (var name in all)
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
-
};
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
-
for (let key of __getOwnPropNames(from))
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
-
}
|
16
|
-
return to;
|
17
|
-
};
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
-
|
20
|
-
// src/middleware/enrichResponseTransmission.middleware.ts
|
21
|
-
var enrichResponseTransmission_middleware_exports = {};
|
22
|
-
__export(enrichResponseTransmission_middleware_exports, {
|
23
|
-
enrichResponseTransmission: () => enrichResponseTransmission
|
24
|
-
});
|
25
|
-
module.exports = __toCommonJS(enrichResponseTransmission_middleware_exports);
|
26
|
-
var import_http = require("@forklaunch/core/http");
|
27
|
-
function enrichResponseTransmission(req, res, next) {
|
28
|
-
console.debug("[MIDDLEWARE] enrichResponseTransmission");
|
29
|
-
const originalSend = res.send;
|
30
|
-
const originalJson = res.json;
|
31
|
-
const originalSetHeader = res.setHeader;
|
32
|
-
res.json = function(data) {
|
33
|
-
res.bodyData = data;
|
34
|
-
const result = originalJson.call(this, data);
|
35
|
-
return result;
|
36
|
-
};
|
37
|
-
res.send = function(data) {
|
38
|
-
if (!res.bodyData) {
|
39
|
-
res.bodyData = data;
|
40
|
-
res.statusCode = res._status_code;
|
41
|
-
}
|
42
|
-
return (0, import_http.enrichExpressLikeSend)(
|
43
|
-
this,
|
44
|
-
req,
|
45
|
-
res,
|
46
|
-
originalSend,
|
47
|
-
data,
|
48
|
-
!res.cors && (res._cork && !res._corked || !res._cork)
|
49
|
-
);
|
50
|
-
};
|
51
|
-
res.setHeader = function(name, value) {
|
52
|
-
let stringifiedValue;
|
53
|
-
if (Array.isArray(value)) {
|
54
|
-
stringifiedValue = value.map(
|
55
|
-
(v) => typeof v !== "string" ? JSON.stringify(v) : v
|
56
|
-
);
|
57
|
-
} else {
|
58
|
-
stringifiedValue = typeof value !== "string" ? JSON.stringify(value) : value;
|
59
|
-
}
|
60
|
-
return originalSetHeader.call(this, name, stringifiedValue);
|
61
|
-
};
|
62
|
-
next();
|
63
|
-
}
|
64
|
-
// Annotate the CommonJS export names for ESM import in node:
|
65
|
-
0 && (module.exports = {
|
66
|
-
enrichResponseTransmission
|
67
|
-
});
|
@@ -1,44 +0,0 @@
|
|
1
|
-
// src/middleware/enrichResponseTransmission.middleware.ts
|
2
|
-
import {
|
3
|
-
enrichExpressLikeSend
|
4
|
-
} from "@forklaunch/core/http";
|
5
|
-
function enrichResponseTransmission(req, res, next) {
|
6
|
-
console.debug("[MIDDLEWARE] enrichResponseTransmission");
|
7
|
-
const originalSend = res.send;
|
8
|
-
const originalJson = res.json;
|
9
|
-
const originalSetHeader = res.setHeader;
|
10
|
-
res.json = function(data) {
|
11
|
-
res.bodyData = data;
|
12
|
-
const result = originalJson.call(this, data);
|
13
|
-
return result;
|
14
|
-
};
|
15
|
-
res.send = function(data) {
|
16
|
-
if (!res.bodyData) {
|
17
|
-
res.bodyData = data;
|
18
|
-
res.statusCode = res._status_code;
|
19
|
-
}
|
20
|
-
return enrichExpressLikeSend(
|
21
|
-
this,
|
22
|
-
req,
|
23
|
-
res,
|
24
|
-
originalSend,
|
25
|
-
data,
|
26
|
-
!res.cors && (res._cork && !res._corked || !res._cork)
|
27
|
-
);
|
28
|
-
};
|
29
|
-
res.setHeader = function(name, value) {
|
30
|
-
let stringifiedValue;
|
31
|
-
if (Array.isArray(value)) {
|
32
|
-
stringifiedValue = value.map(
|
33
|
-
(v) => typeof v !== "string" ? JSON.stringify(v) : v
|
34
|
-
);
|
35
|
-
} else {
|
36
|
-
stringifiedValue = typeof value !== "string" ? JSON.stringify(value) : value;
|
37
|
-
}
|
38
|
-
return originalSetHeader.call(this, name, stringifiedValue);
|
39
|
-
};
|
40
|
-
next();
|
41
|
-
}
|
42
|
-
export {
|
43
|
-
enrichResponseTransmission
|
44
|
-
};
|