Skip to content

Instantly share code, notes, and snippets.

@tjmonsi
Created December 15, 2021 05:43
Show Gist options
  • Save tjmonsi/051864dc2d102c7bc10d630cdfc857ef to your computer and use it in GitHub Desktop.
Save tjmonsi/051864dc2d102c7bc10d630cdfc857ef to your computer and use it in GitHub Desktop.
App JS for fastify
import stat from 'fastify-static';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
import { readFileSync } from 'fs';
// ...
app.register(stat, {
root: join(dirname(fileURLToPath(import.meta.url)), './public'),
preCompressed: true
});
app.setNotFoundHandler((_req, res) => res.sendFile('index.html'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment