DenoDDeno
Powered by
dan.the.discloserD
Denoβ€’4y agoβ€’
1 reply
dan.the.discloser

get in oak

In
oak
oak
, how do I check whether a request is the root?

It

- starts with slash
- is of length 1

but is NOT equal to "/"


app.use(async (ctx, next) => {
  console.log({pathname: ctx.request.url.pathname})
  const starts_with_slash = ctx.request.url.pathname.startsWith("/")
  const is_not_slash = (!ctx.request.url.pathname != "/")
  const the_length = ctx.request.url.pathname.length 

  console.log({starts_with_slash})
  console.log({is_not_slash})
  console.log({the_length})
  ...})
  
app.use(async (ctx, next) => {
  console.log({pathname: ctx.request.url.pathname})
  const starts_with_slash = ctx.request.url.pathname.startsWith("/")
  const is_not_slash = (!ctx.request.url.pathname != "/")
  const the_length = ctx.request.url.pathname.length 

  console.log({starts_with_slash})
  console.log({is_not_slash})
  console.log({the_length})
  ...})
  


console output

{ pathname: "/" }
{ starts_with_slash: true }
{ is_not_slash: true }
{ the_length: 1 }
{ pathname: "/" }
{ starts_with_slash: true }
{ is_not_slash: true }
{ the_length: 1 }
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,934Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Get a Parameter Value in Oak
alexp95Aalexp95 / help
3y ago
HTTPS Oak Deno
ivandpfIivandpf / help
3y ago