raiton 5.6.0-beta.4 → 5.7.0-beta.5
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/build/bin/index.mjs +1 -1
- package/package.json +1 -1
- package/source/framework/runtime/bun/server.ts +7 -2
- package/source/framework/runtime/deno/server.ts +2 -0
- package/source/framework/runtime/node/request.ts +5 -0
- package/source/framework/runtime/web/server.ts +4 -1
- package/source/framework/utilities/index.ts +2 -1
- package/source/framework/utilities/ip.util.ts +12 -0
- package/source/types/runtime.ts +1 -0
package/build/bin/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {RuntimeAdapterInterface} from '../../../types'
|
|
2
2
|
import {Logger} from "@protorians/logger";
|
|
3
|
+
import {getRealIp} from "../../utilities";
|
|
3
4
|
|
|
4
5
|
export const bunRuntime: RuntimeAdapterInterface = {
|
|
5
6
|
createServer(handler) {
|
|
@@ -14,17 +15,21 @@ export const bunRuntime: RuntimeAdapterInterface = {
|
|
|
14
15
|
server = Bun.serve({
|
|
15
16
|
port,
|
|
16
17
|
hostname,
|
|
17
|
-
fetch: async (request: Request) => {
|
|
18
|
+
fetch: async (request: Request, server: any) => {
|
|
18
19
|
let responseBody: any
|
|
19
20
|
let statusCode = 200
|
|
20
21
|
const headers = new Headers()
|
|
21
22
|
|
|
23
|
+
const remoteAddress = server.requestIP(request)?.address
|
|
24
|
+
|
|
22
25
|
await handler(
|
|
23
26
|
{
|
|
24
27
|
method: request.method,
|
|
25
28
|
url: request.url,
|
|
26
29
|
headers: request.headers as any,
|
|
27
|
-
body: request.body ? request.body : null
|
|
30
|
+
body: request.body ? request.body : null,
|
|
31
|
+
remoteAddress,
|
|
32
|
+
ip: getRealIp(request.headers, remoteAddress)
|
|
28
33
|
},
|
|
29
34
|
{
|
|
30
35
|
status(code) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {RuntimeAdapterInterface, RuntimeRequestInterface, RuntimeReplyInterface} from '../../../types'
|
|
2
2
|
import {Logger} from "@protorians/logger";
|
|
3
|
+
import {getRealIp} from "../../utilities";
|
|
3
4
|
|
|
4
5
|
// class DenoRequest implements RuntimeRequestInterface {
|
|
5
6
|
// constructor(private req: Request) {}
|
|
@@ -12,6 +13,7 @@ import {Logger} from "@protorians/logger";
|
|
|
12
13
|
// get file(): any { return undefined; }
|
|
13
14
|
// get files(): any { return undefined; }
|
|
14
15
|
// get remoteAddress(): string | undefined { return undefined; }
|
|
16
|
+
// get ip(): string | undefined { return getRealIp(this.headers, this.remoteAddress); }
|
|
15
17
|
// }
|
|
16
18
|
|
|
17
19
|
// class DenoReply implements RuntimeReplyInterface {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IncomingMessage } from 'node:http'
|
|
2
2
|
import type { RuntimeRequestInterface } from '../../../types'
|
|
3
|
+
import {getRealIp} from "../../utilities";
|
|
3
4
|
|
|
4
5
|
export class NodeRequest implements RuntimeRequestInterface {
|
|
5
6
|
constructor(public req: IncomingMessage) {
|
|
@@ -44,4 +45,8 @@ export class NodeRequest implements RuntimeRequestInterface {
|
|
|
44
45
|
get remoteAddress(): string | undefined {
|
|
45
46
|
return this.req.socket?.remoteAddress
|
|
46
47
|
}
|
|
48
|
+
|
|
49
|
+
get ip(): string | undefined {
|
|
50
|
+
return getRealIp(this.headers, this.remoteAddress)
|
|
51
|
+
}
|
|
47
52
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// import {RuntimeAdapterInterface} from '../../../types'
|
|
2
2
|
// import {Logger} from "@protorians/logger";
|
|
3
|
+
// import {getRealIp} from "../../utilities";
|
|
3
4
|
//
|
|
4
5
|
// export const webRuntime: RuntimeAdapterInterface = {
|
|
5
6
|
// createServer(handler) {
|
|
@@ -18,7 +19,9 @@
|
|
|
18
19
|
// method: request.method,
|
|
19
20
|
// url: request.url,
|
|
20
21
|
// headers: request.headers,
|
|
21
|
-
// body: request.body ? request.body : null
|
|
22
|
+
// body: request.body ? request.body : null,
|
|
23
|
+
// remoteAddress: undefined,
|
|
24
|
+
// ip: getRealIp(request.headers, undefined)
|
|
22
25
|
// },
|
|
23
26
|
// {
|
|
24
27
|
// status(code) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the real IP address from headers or remote address
|
|
3
|
+
* @param headers
|
|
4
|
+
* @param remoteAddress
|
|
5
|
+
*/
|
|
6
|
+
export const getRealIp = (headers: Headers, remoteAddress?: string): string | undefined => {
|
|
7
|
+
const forwardedFor = headers.get('x-forwarded-for');
|
|
8
|
+
if (forwardedFor) {
|
|
9
|
+
return forwardedFor.split(',')[0].trim();
|
|
10
|
+
}
|
|
11
|
+
return headers.get('x-real-ip') || remoteAddress;
|
|
12
|
+
}
|
package/source/types/runtime.ts
CHANGED