Static file serving

Sequoia also offers you two ways of serving static files

Router.static

You can define a folder to serve static files from right in your application code like so:

// static.ts
import { Application, HTTPResponse, HTTPStatus, Router } from 'jsr:@sequoia/sequoia'

const app = new Application()
const router = new Router()

router.GET('/', (context) => {
    return new HTTPResponse({
        status: HTTPStatus.SUCCESS,
        body: 'Head over to ' + context.request.url + '/static/text.txt',
    })
})

router.static('/static', `${Deno.cwd()}/examples/static`)

app.useRouter(router)
await app.listen({ port: 8000 })

After that just create a file at /static/text.txt and run deno run --allow-net --allow-read=static static.ts

CLI

Another way of serving static files is through CLI, and there are 2 approaches. Let's assume we still have a text file at /static/text.txt

1. Using deno run

To serve it we just call deno run --allow-net --allow-read=static https://deno.land/x/sequoia@v0.6.2/serve.ts ./static

But this command is too long because of the URL in it. So there is the better way to do it

2. Using deno install

First we need to install the serve.ts utility from https://deno.land/x/sequoia@v0.6.2. We can do this with this command: deno install --allow-net --allow-read -n serve https://deno.land/x/sequoia@v0.6.2/serve.ts

After the script is installed, add the path to your environment: export PATH="$HOME/.deno/bin:$PATH". Read more about deno install here

And finally run this script with the parameters: serve ./static --hostname 127.0.0.1 --port 80

Now you can use serve in your console everywhere you want