#Pathname prefix in serve()

1 messages · Page 1 of 1 (latest)

copper kindle
#

Hi, I was wondering if it's possible to only handle requests coming from specific prefix within pathname like:
localhost:8000/api
I'm using std serve.

crystal sorrel
#
let { pathname } = new URL(request.url);

if (pathname.includes('/api')) {
  //do something with api
}
copper kindle
#

thanks, but in handler function for serve, is it possible to not return any response?

crystal sorrel
#

I don't think so, but you could just send an empty or custom response.

supple scroll
#

why would you not send a response

#

if no response was sent back the client would just be left hanging but with an open tcp connection

copper kindle
#

I'm creating simple api using std that would run alongside with my page made in deno fresh. I thoguht that calling 404 response from api would interfere with fresh pages? Not sure about that so i may be just wrong. thanks for the answers tho cookie_deno

crystal sorrel
#

Fresh handles apis very effectively. Just use Fresh. Let me know if you need an example.