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.
@@ -4817,7 +4817,7 @@ var {
4817
4817
  Help
4818
4818
  } = import__.default;
4819
4819
  // package.json
4820
- var version = "5.6.0-beta.4";
4820
+ var version = "5.7.0-beta.5";
4821
4821
 
4822
4822
  // source/bin/cli.ts
4823
4823
  var CLI = new Command;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "raiton",
3
- "version": "5.6.0-beta.4",
3
+ "version": "5.7.0-beta.5",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Modular TypeScript Backend Framework with Dependency Injection, Plugins, Controllers, Middleware and Hot Reloading.",
@@ -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) {
@@ -4,4 +4,5 @@ export * from "./artifact.util"
4
4
  export * from "./json.util"
5
5
  export * from "./path.util"
6
6
  export * from "./cookie.util"
7
- export * from "./openapi.utils"
7
+ export * from "./openapi.utils"
8
+ export * from "./ip.util"
@@ -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
+ }
@@ -18,6 +18,7 @@ export interface RuntimeRequestInterface {
18
18
  file?: any
19
19
  files?: any
20
20
  remoteAddress?: string
21
+ ip?: string
21
22
  }
22
23
 
23
24
  export type RuntimeHandlerCallable = (req: RuntimeRequestInterface, reply: RuntimeReplyInterface) => Promise<void>