framework-do-dede 6.2.1 → 6.2.3
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/http/http-server.js
CHANGED
|
@@ -42,8 +42,24 @@ export default class HttpServer {
|
|
|
42
42
|
(this.framework[method])(route, async ({ headers, set, query, params, body, request }) => {
|
|
43
43
|
headers['ip'] = this.framework.server?.requestIP(request).address;
|
|
44
44
|
set.status = httpServerParams.statusCode ?? 200;
|
|
45
|
+
const protocol = String(headers?.['x-forwarded-proto'] ?? '').split(',')[0].trim()
|
|
46
|
+
|| (typeof request?.url === 'string' && request.url.startsWith('https://') ? 'https' : 'http');
|
|
47
|
+
let hostFromUrl = '';
|
|
48
|
+
if (typeof request?.url === 'string' && request.url.includes('://')) {
|
|
49
|
+
try {
|
|
50
|
+
hostFromUrl = new URL(request.url).host;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
hostFromUrl = '';
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const hostRaw = (headers?.host ?? headers?.Host ?? hostFromUrl) || 'localhost';
|
|
57
|
+
const host = String(hostRaw).startsWith('http://') || String(hostRaw).startsWith('https://')
|
|
58
|
+
? String(hostRaw)
|
|
59
|
+
: `${protocol}://${hostRaw}`;
|
|
45
60
|
const output = await handler({
|
|
46
61
|
setStatus: (statusCode) => set.status = statusCode,
|
|
62
|
+
host,
|
|
47
63
|
headers,
|
|
48
64
|
query,
|
|
49
65
|
params,
|
|
@@ -71,8 +87,16 @@ export default class HttpServer {
|
|
|
71
87
|
this.framework[method](route, async (request, res) => {
|
|
72
88
|
request.headers['ip'] = request.ip;
|
|
73
89
|
res.status(httpServerParams.statusCode ?? 200);
|
|
90
|
+
const protocol = String(request.headers?.['x-forwarded-proto'] ?? '').split(',')[0].trim()
|
|
91
|
+
|| request.protocol
|
|
92
|
+
|| 'http';
|
|
93
|
+
const hostRaw = request.headers?.host ?? request.headers?.Host ?? request.hostname ?? 'localhost';
|
|
94
|
+
const host = String(hostRaw).startsWith('http://') || String(hostRaw).startsWith('https://')
|
|
95
|
+
? String(hostRaw)
|
|
96
|
+
: `${protocol}://${hostRaw}`;
|
|
74
97
|
const output = await handler({
|
|
75
98
|
setStatus: (statusCode) => res.status(statusCode),
|
|
99
|
+
host,
|
|
76
100
|
headers: request.headers,
|
|
77
101
|
query: request.query,
|
|
78
102
|
params: request.params,
|
|
@@ -9,7 +9,7 @@ export class HttpRequestMapper {
|
|
|
9
9
|
filterBody = { ...normalizeBody, ...filterBody };
|
|
10
10
|
}
|
|
11
11
|
const mergedParams = { ...filterHeaders, ...filterParams, ...filterQueryParams, ...filterBody };
|
|
12
|
-
return { data: mergedParams, context: {} };
|
|
12
|
+
return { data: mergedParams, context: { host: input.host } };
|
|
13
13
|
}
|
|
14
14
|
filter(params, filterParams) {
|
|
15
15
|
const filter = {};
|