Skip to content

Check if a file exists #315

Answered by Hunam6
Hunam6 asked this question in Q&A
Discussion options

You must be logged in to vote

Sorry my bad, nothing to do with Oak, just use fs.
If anyone intrested:

import {exists} from 'https://deno.land/std/fs/mod.ts'
app.use(async ctx => {
  if (await exists('./assets' + ctx.request.url.pathname)) await send(ctx, ctx.request.url.pathname, {root: './assets'})
  else {
    ctx.response.body = 'error 404'
    ctx.response.status = 404
  }
})

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Hunam6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant