Add static file server
This commit is contained in:
parent
d962bfc01e
commit
5a40eab800
3 changed files with 75 additions and 0 deletions
17
src/endpoints/files.ts
Normal file
17
src/endpoints/files.ts
Normal 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;
|
||||
|
|
@ -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)`,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue