taiwannumberone
taiwannumberone14mo ago

Pathname prefix in serve()

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.
6 Replies
NDH
NDH14mo ago
let { pathname } = new URL(request.url);

if (pathname.includes('/api')) {
//do something with api
}
let { pathname } = new URL(request.url);

if (pathname.includes('/api')) {
//do something with api
}
taiwannumberone
taiwannumberone14mo ago
thanks, but in handler function for serve, is it possible to not return any response?
NDH
NDH14mo ago
I don't think so, but you could just send an empty or custom response.
ioB
ioB14mo ago
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
taiwannumberone
taiwannumberone14mo ago
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:1002977285734932480>
NDH
NDH14mo ago
Fresh handles apis very effectively. Just use Fresh. Let me know if you need an example. This api named post - /routes/api/post.ts -, justs relays messages to all BroadcastChannel subscribers. (all isolates) https://github.com/nhrones/FreshDiceRTC/blob/master/routes/api/post.ts Make sure to run deno-task-start after you add a route.
More Posts
embed typescript playground to web pagesome programming language guides like the rust book lets you directly edit and run code in their docUsing deno-lambda for AWS SAMI'm having issues trying to run deno-lambda (https://github.com/hayd/deno-lambda) locally. (I haven'How to monetize an app?I would like to monetize my apps in a certain way. Mabye limit some features. How to approach monetiimporting scoped NPM packages from other registriesIn node, I can create an `.npmrc` that has rules like this: ``` @custom:registry=https://npm.examplEmbedding, snapshotting, and 7-bit ascii requirementWhat are the differences in how a code module is processed when using `load_side_module()` versus whStandard setup of a monorepo that includes frontend and backend TypeScript code for one appHello friends, I'm new to Deno and have what I feel is a relatively simple use case, but I've struggHow can I import https://github.com/ensdomains/ensjs-v3/tree/main in my denoThis is npm package. I want to use it in my deno project. How can I achive it? I am trying this: `imTesting that advanced types workI have a bunch of pretty advanced types, with generics and inferences all over the place. What woulHow can I reattach a debugger after disconnecting?I want to be able to start deno from a command line, but be able to attach to it from VSCode. I actPass string from TS to dll and return the passed string. (Like echo)Hey I am currently trying to understand the communication between a dll and my TS program. Currently