D
Deno

help

Pathname prefix in serve()

Ttaiwannumberone5/8/2023
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.
ABAltair 680b5/8/2023
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
}
Ttaiwannumberone5/8/2023
thanks, but in handler function for serve, is it possible to not return any response?
ABAltair 680b5/8/2023
I don't think so, but you could just send an empty or custom response.
IioB5/8/2023
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
Ttaiwannumberone5/8/2023
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>
ABAltair 680b5/8/2023
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.

Looking for more? Join the community!

Recommended 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 monetiStandard 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. Currentlydeno-deploy limits on file storage?When deploying static files via deployctl, what are the storage limits / costs per GB? Couldn't findDoes anyone have a working OpenCL deno example?How can I use opencl with deno? Any examples?absolute imports in fresh?how do you get this accomplished?PhpStorm not resolving local import with import_map.jsonDeno Version : deno 1.33.0 (release, aarch64-apple-darwin) v8 11.4.183.1 typescript 5.0.3 PhpStorm how to cancel test watchon linux. ran `deno test -A --watch tools/json_tools/examples/*.ts` and `ctrl+c` does not seems to Sentry DenoOsUptime is not a function issueI'm using `npm:@sentry/node@7.49.0` and the following script to test the integration ```TypeScript /Property 'openKv' does not exist on type 'typeof Deno'. VSCodeSuch as the title say, I cant get the LSP to recognize openKv in the Deno namespace... deno 1.32.5+Import from direct URL works fine, but NOT via deps.ts``` // ./lib/foobar1.ts // everything is fine import { z } from "https://deno.land/x/zod@v3.21.4/modSmall Deno Script to upload to my server not working due to not being able to be run on CentOSAll my clients run Ubuntu or Debian, and the script will not run on CentOS due to the problem of a GEmpty output in Deno.CommandI’m trying to run the command `git log —grep='.'` from Deno. However, it always returns an empty out