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

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 }
1 Reply
Sorikairo
Sorikairo2y ago
Your “is_not_slash” is in fact doing “is_slash” because of the negation at the beginning I believe ?