From 5e2445e9728457e3b2ec35a572e557ce018ee57e Mon Sep 17 00:00:00 2001 From: Aral Roca Date: Tue, 3 Oct 2023 21:37:37 +0200 Subject: [PATCH] feat: add getIP method in request context --- bun.lockb | Bin 5005 -> 5164 bytes package.json | 6 +++--- src/cli/serve.tsx | 2 ++ src/core/request-context/index.ts | 4 +++- src/types/index.d.ts | 1 + 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bun.lockb b/bun.lockb index 557c7d8c7264739039e24108d7a8a5508bb47041..8cf7ff0e36d82bbb5b64dffbc1df08b740fe0739 100755 GIT binary patch delta 1102 zcmeBGU!yTWPl@;WZ}qOPitkU)O`B=rZT@5K?f(zB7-lRvur%GQE25rrj_||)i$G@v z1_n+BhK8h~%;H2Kn+u3#f&2tUi1Mh;#Mp!Nu$1kfr5_Q?~Ow85g8Kv8RSQN|aOJDKb`^?(j@1IjT0Rhu)G zOy*>^XFN06li8k=hnax^XnO<59COBq$tQs_6E<_Qq%b;Ec(IE&~~^P?n>D>m*D$&M;$3+lJlZ(ZzezU0D=vl0gVM<&Oz zNjSK(aG1ozc=$-(e)Dm*&xaU#EPzgGXcf%*|WbnwciMG750QVv=RDBiH-Q4qW}rmgaf}3=FU&^gr`_ zgvk47OAbZ@Jp(;sphsYdtolv**$$!CN*s*pKv5ZBTuffTD98i2Wqn0)^>!x4I3u7fKs3A zz2Xd@LN)U%lGm1$YzC?Y=~GDE`X=<}$-2WpzA%tKiBUsEzp1SJ1k}7K!jlvD6(-N; zWo2ZT+`zAHZ3uL!iEeUYUSd(Do{@o(v7v#1afqRbfuV_IQfZ!UNo7H5F?Q+6h62)) zZ}3am?;LJgK<$0rvd+4|nbP~nu-E-|Wqg(e1A1e!1~ zFmN(3G$a*e7AFGPTtF-fIMOcumW%qhr7 z)H7jdb`bpSIep6X$pwrO0vmx65kO;r?g4|z4vZQgQv`&7TCK52FixD@$z;!Y9VqPv zlxCVdk;$AgS`m+-%R-ktK8AGcT5hN@QevAv(MnqMhW&|4!&=lt!KdQI-epNVT%PWZUa zv#Edbw8?8(CF)a`ubJqo0Kn7}CGFgvPYH|Rh+-3)^er5{;Jwt?l{%4+#5P2VM$-$@&^bs#G<-qb) z^_%pw9YU{_I2aA}4D^f`7$(o>m6nF(t^@(S(!kSJmzWq0jeycX6MZM!@) zWK5jg%_k`h%Xu}iEbA+ZtG6>T#(~rtFfcSt-p?m#3(Juw*W2w%39(UNVl>b*(=!IT z1C~dB@+xf=by)C$i7^rw2?9XZg#oiP2!u@*<#*I-fbzZqGcpKp*_2w?DHtjgXI7== zr|AG$i8-0+dHHEvlTYxgiviuKXP^tsiAkk-x+Rqbsl}5G1*Ipu3P?>pFQhPer+@%A dlA_5Mgybi`7BFK5YMrbi=m?@WX9yl)0svUCPGkT8 diff --git a/package.json b/package.json index d5dd1bd1a..05c455aac 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/cli/serve.tsx b/src/cli/serve.tsx index 4ea7ab762..d793661e6 100644 --- a/src/cli/serve.tsx +++ b/src/cli/serve.tsx @@ -78,6 +78,8 @@ Bun.serve({ if (redirect) return redirect; } + request.getIP = () => server.requestIP(req); + return ( handleRequest(request, isAnAsset) // 500 page diff --git a/src/core/request-context/index.ts b/src/core/request-context/index.ts index f5deda4de..c3cdeef20 100644 --- a/src/core/request-context/index.ts +++ b/src/core/request-context/index.ts @@ -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 { @@ -13,10 +13,12 @@ export default class RequestContext extends Request { locale: '', t: () => '', } + this.getIP = () => null; } route?: MatchedRoute; context: Map; i18n: I18nFromRequest; + getIP: () => SocketAddress | null; ws?: ServerWebSocket; } diff --git a/src/types/index.d.ts b/src/types/index.d.ts index bcb284015..19852407e 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -5,6 +5,7 @@ export interface RequestContext extends Request { route?: MatchedRoute; i18n: I18nFromRequest; ws?: ServerWebSocket; + getIP: () => SocketAddress | null; } type Props = Record & {