Skip to content

Commit

Permalink
feat: add getIP method in request context
Browse files Browse the repository at this point in the history
  • Loading branch information
aralroca committed Oct 3, 2023
1 parent ef3b3c3 commit 5e2445e
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
Binary file modified bun.lockb
Binary file not shown.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
"create-brisa-app": "./create-brisa-app.sh"
},
"devDependencies": {
"@happy-dom/global-registrator": "12.0.1",
"bun-types": "1.0.2",
"brisa": "0.1.0-alpha.4"
"@happy-dom/global-registrator": "12.7.0",
"bun-types": "1.0.4-canary.20231003T140149",
"brisa": "0.0.3"
},
"peerDependencies": {
"typescript": "5.2.2"
Expand Down
2 changes: 2 additions & 0 deletions src/cli/serve.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Bun.serve({
if (redirect) return redirect;
}

request.getIP = () => server.requestIP(req);

return (
handleRequest(request, isAnAsset)
// 500 page
Expand Down
4 changes: 3 additions & 1 deletion src/core/request-context/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MatchedRoute, ServerWebSocket } from "bun";
import { MatchedRoute, ServerWebSocket, SocketAddress } from "bun";
import { I18nFromRequest } from "../../types";

export default class RequestContext extends Request {
Expand All @@ -13,10 +13,12 @@ export default class RequestContext extends Request {
locale: '',
t: () => '',
}
this.getIP = () => null;
}

route?: MatchedRoute;
context: Map<string, any>;
i18n: I18nFromRequest;
getIP: () => SocketAddress | null;
ws?: ServerWebSocket<unknown>;
}
1 change: 1 addition & 0 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface RequestContext extends Request {
route?: MatchedRoute;
i18n: I18nFromRequest;
ws?: ServerWebSocket<unknown>;
getIP: () => SocketAddress | null;
}

type Props = Record<string, unknown> & {
Expand Down

0 comments on commit 5e2445e

Please sign in to comment.