0
0
Fork 0

Add static file server

This commit is contained in:
Oliver Akins 2022-07-31 17:48:57 -06:00
parent d962bfc01e
commit 5a40eab800
No known key found for this signature in database
GPG key ID: 3C2014AF9457AF99
3 changed files with 75 additions and 0 deletions

17
src/endpoints/files.ts Normal file
View file

@ -0,0 +1,17 @@
import { ServerRoute } from "@hapi/hapi";
const data: ServerRoute = {
method: `GET`, path: `/{path*}`,
options: {
auth: false,
},
handler: {
directory: {
path: `.`,
index: true,
redirectToSlash: true,
defaultExtension: `html`,
},
},
};
export default data;

View file

@ -3,6 +3,7 @@ import "module-alias/register";
// Begin personal code
import { Server, Request } from "@hapi/hapi";
import inert from "@hapi/inert";
import basic from "@hapi/basic";
import path from "path";
import glob from "glob";
@ -42,6 +43,9 @@ async function init() {
const server = new Server({
port: config.server.port,
routes: {
files: {
relativeTo: path.join(__dirname, `../docs`),
},
cors: {
origin: [`*`],
credentials: true,
@ -74,6 +78,8 @@ async function init() {
});
server.auth.default(`basic`);
await server.register(inert);
// Register all the routes
let files = glob.sync(
`endpoints/**/!(*.map)`,