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

get in oak

In 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})
  ...})
  


console output

{ pathname: "/" }
{ starts_with_slash: true }
{ is_not_slash: true }
{ the_length: 1 }
Was this page helpful?