Skip to content

Instantly share code, notes, and snippets.

@briward
Last active November 13, 2024 16:31
Show Gist options
  • Save briward/878fc87cca9005a9fe7e2be54f7e910a to your computer and use it in GitHub Desktop.
Save briward/878fc87cca9005a9fe7e2be54f7e910a to your computer and use it in GitHub Desktop.
Loading static files with Raptor Router
function template(name: string) {
const decoder = new TextDecoder('utf-8');
const text = Deno.readFileSync(
`${Deno.cwd()}/templates/${name}.html`
);
return decoder.decode(text);
}
export default function asset(name: string, extension: string) {
const decoder = new TextDecoder('utf-8');
const text = Deno.readFileSync(
`${Deno.cwd()}/public/${name}.${extension}`
);
return decoder.decode(text);
}
const router = new Router();
router.add(new Route({
name: 'static',
pathname: `/public/:path+.css`,
method: HttpMethod.GET,
handler: () => asset('style', 'css')
}));
router.add(new Route({
name: 'index',
pathname: '/',
method: HttpMethod.GET,
handler: () => template('index')
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment