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

52
pnpm-lock.yaml generated
View file

@ -4,9 +4,11 @@ specifiers:
'@hapi/basic': ^6.0.0 '@hapi/basic': ^6.0.0
'@hapi/boom': ^10.0.0 '@hapi/boom': ^10.0.0
'@hapi/hapi': ^20.2.2 '@hapi/hapi': ^20.2.2
'@hapi/inert': ^7.0.0
'@types/glob': ^7.2.0 '@types/glob': ^7.2.0
'@types/hapi__basic': ^5.1.2 '@types/hapi__basic': ^5.1.2
'@types/hapi__hapi': ^20.0.12 '@types/hapi__hapi': ^20.0.12
'@types/hapi__inert': ^5.2.3
'@types/node': ^18.0.6 '@types/node': ^18.0.6
'@types/uuid': ^8.3.4 '@types/uuid': ^8.3.4
glob: ^8.0.3 glob: ^8.0.3
@ -19,6 +21,7 @@ dependencies:
'@hapi/basic': 6.0.0 '@hapi/basic': 6.0.0
'@hapi/boom': 10.0.0 '@hapi/boom': 10.0.0
'@hapi/hapi': 20.2.2 '@hapi/hapi': 20.2.2
'@hapi/inert': 7.0.0
glob: 8.0.3 glob: 8.0.3
joi: 17.6.0 joi: 17.6.0
module-alias: 2.2.2 module-alias: 2.2.2
@ -29,6 +32,7 @@ devDependencies:
'@types/glob': 7.2.0 '@types/glob': 7.2.0
'@types/hapi__basic': 5.1.2 '@types/hapi__basic': 5.1.2
'@types/hapi__hapi': 20.0.12 '@types/hapi__hapi': 20.0.12
'@types/hapi__inert': 5.2.3
'@types/node': 18.0.6 '@types/node': 18.0.6
'@types/uuid': 8.3.4 '@types/uuid': 8.3.4
@ -47,6 +51,12 @@ packages:
'@hapi/hoek': 9.3.0 '@hapi/hoek': 9.3.0
dev: false dev: false
/@hapi/ammo/6.0.0:
resolution: {integrity: sha512-lhX7SYtWScQaeAIL5XnE54WzyDgS5RXVeEtFEovyZcTdVzTYbo0nem56Bwko1PBcRxRUIw1v2tMb6sjFs6vEwg==}
dependencies:
'@hapi/hoek': 10.0.0
dev: false
/@hapi/b64/5.0.0: /@hapi/b64/5.0.0:
resolution: {integrity: sha512-ngu0tSEmrezoiIaNGG6rRvKOUkUuDdf4XTPnONHGYfSGRmDqPZX5oJL6HAdKTo1UQHECbdB4OzhWrfgVppjHUw==} resolution: {integrity: sha512-ngu0tSEmrezoiIaNGG6rRvKOUkUuDdf4XTPnONHGYfSGRmDqPZX5oJL6HAdKTo1UQHECbdB4OzhWrfgVppjHUw==}
dependencies: dependencies:
@ -77,6 +87,13 @@ packages:
'@hapi/hoek': 9.3.0 '@hapi/hoek': 9.3.0
dev: false dev: false
/@hapi/bounce/3.0.0:
resolution: {integrity: sha512-L0G4NcwwOYRhpcXeL76hNrLTUcObqtZMB3z4kcRVUZcR/w3v6C5Q1cTElV4/V7og1fG+wOyDR55UMFA+tWfhtA==}
dependencies:
'@hapi/boom': 10.0.0
'@hapi/hoek': 10.0.0
dev: false
/@hapi/bourne/2.1.0: /@hapi/bourne/2.1.0:
resolution: {integrity: sha512-i1BpaNDVLJdRBEKeJWkVO6tYX6DMFBuwMhSuWqLsY4ufeTKGVuV5rBsUhxPayXqnnWHgXUAmWK16H/ykO5Wj4Q==} resolution: {integrity: sha512-i1BpaNDVLJdRBEKeJWkVO6tYX6DMFBuwMhSuWqLsY4ufeTKGVuV5rBsUhxPayXqnnWHgXUAmWK16H/ykO5Wj4Q==}
@ -158,6 +175,17 @@ packages:
/@hapi/hoek/9.3.0: /@hapi/hoek/9.3.0:
resolution: {integrity: sha512-/c6rf4UJlmHlC9b5BaNvzAcFv7HZ2QHaV0D4/HNlBdvFnvQq8RI4kYdhyPCl7Xj+oWvTWQ8ujhqS53LIgAe6KQ==} resolution: {integrity: sha512-/c6rf4UJlmHlC9b5BaNvzAcFv7HZ2QHaV0D4/HNlBdvFnvQq8RI4kYdhyPCl7Xj+oWvTWQ8ujhqS53LIgAe6KQ==}
/@hapi/inert/7.0.0:
resolution: {integrity: sha512-aJvH8rKYF42YY/XZLtq5LOWyk71GRIlcqRgvRyz+XQnj2DTdSZeerUcsxV2kyzJVm9gdemVwHp00foLfKadbMg==}
dependencies:
'@hapi/ammo': 6.0.0
'@hapi/boom': 10.0.0
'@hapi/bounce': 3.0.0
'@hapi/hoek': 10.0.0
'@hapi/validate': 2.0.0
lru-cache: 7.13.1
dev: false
/@hapi/iron/6.0.0: /@hapi/iron/6.0.0:
resolution: {integrity: sha512-zvGvWDufiTGpTJPG1Y/McN8UqWBu0k/xs/7l++HVU535NLHXsHhy54cfEMdW7EjwKfbBfM9Xy25FmTiobb7Hvw==} resolution: {integrity: sha512-zvGvWDufiTGpTJPG1Y/McN8UqWBu0k/xs/7l++HVU535NLHXsHhy54cfEMdW7EjwKfbBfM9Xy25FmTiobb7Hvw==}
dependencies: dependencies:
@ -246,12 +274,25 @@ packages:
dependencies: dependencies:
'@hapi/hoek': 9.3.0 '@hapi/hoek': 9.3.0
/@hapi/topo/6.0.0:
resolution: {integrity: sha512-aorJvN1Q1n5xrZuA50Z4X6adI6VAM2NalIVm46ALL9LUvdoqhof3JPY69jdJH8asM3PsWr2SUVYzp57EqUP41A==}
dependencies:
'@hapi/hoek': 10.0.0
dev: false
/@hapi/validate/1.1.3: /@hapi/validate/1.1.3:
resolution: {integrity: sha512-/XMR0N0wjw0Twzq2pQOzPBZlDzkekGcoCtzO314BpIEsbXdYGthQUbxgkGDf4nhk1+IPDAsXqWjMohRQYO06UA==} resolution: {integrity: sha512-/XMR0N0wjw0Twzq2pQOzPBZlDzkekGcoCtzO314BpIEsbXdYGthQUbxgkGDf4nhk1+IPDAsXqWjMohRQYO06UA==}
dependencies: dependencies:
'@hapi/hoek': 9.3.0 '@hapi/hoek': 9.3.0
'@hapi/topo': 5.1.0 '@hapi/topo': 5.1.0
/@hapi/validate/2.0.0:
resolution: {integrity: sha512-w5m8MvBgqGndbMIB+AWmXTb8CLtF1DlIxbnbAHNAo7aFuNQuI1Ywc2e0zDLK5fbFXDoqRzNrHnC7JjNJ+hDigw==}
dependencies:
'@hapi/hoek': 10.0.0
'@hapi/topo': 6.0.0
dev: false
/@hapi/vise/4.0.0: /@hapi/vise/4.0.0:
resolution: {integrity: sha512-eYyLkuUiFZTer59h+SGy7hUm+qE9p+UemePTHLlIWppEd+wExn3Df5jO04bFQTm7nleF5V8CtuYQYb+VFpZ6Sg==} resolution: {integrity: sha512-eYyLkuUiFZTer59h+SGy7hUm+qE9p+UemePTHLlIWppEd+wExn3Df5jO04bFQTm7nleF5V8CtuYQYb+VFpZ6Sg==}
dependencies: dependencies:
@ -308,6 +349,12 @@ packages:
joi: 17.6.0 joi: 17.6.0
dev: true dev: true
/@types/hapi__inert/5.2.3:
resolution: {integrity: sha512-I1mWQrEc7oMqGtofT0rwBgRBCBurz0wNzbq8QZsHWR+aXM0bk1j9GA6zwyGIeO53PNl2C1c2kpXlc084xCV+Tg==}
dependencies:
'@types/hapi__hapi': 20.0.12
dev: true
/@types/hapi__mimos/4.1.4: /@types/hapi__mimos/4.1.4:
resolution: {integrity: sha512-i9hvJpFYTT/qzB5xKWvDYaSXrIiNqi4ephi+5Lo6+DoQdwqPXQgmVVOZR+s3MBiHoFqsCZCX9TmVWG3HczmTEQ==} resolution: {integrity: sha512-i9hvJpFYTT/qzB5xKWvDYaSXrIiNqi4ephi+5Lo6+DoQdwqPXQgmVVOZR+s3MBiHoFqsCZCX9TmVWG3HczmTEQ==}
dependencies: dependencies:
@ -381,6 +428,11 @@ packages:
'@sideway/formula': 3.0.0 '@sideway/formula': 3.0.0
'@sideway/pinpoint': 2.0.0 '@sideway/pinpoint': 2.0.0
/lru-cache/7.13.1:
resolution: {integrity: sha512-CHqbAq7NFlW3RSnoWXLJBxCWaZVBrfa9UEHId2M3AW8iEBurbqduNexEUCGc3SHc6iCYXNJCDi903LajSVAEPQ==}
engines: {node: '>=12'}
dev: false
/mime-db/1.52.0: /mime-db/1.52.0:
resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==} resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==}
engines: {node: '>= 0.6'} engines: {node: '>= 0.6'}

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