Static and single page application plugin for hapi.js. Spazy uses the tried and true inert to handle the file serving.
npm i spazy --save
- hapi v18.X.X
- inert v5.X.X
const Hapi = require('@hapi/hapi');
const Inert = require('@hapi/inert');
const Spazy = require('spazy');
const options = { port: 8080 };
const server = new Hapi.Server(options);
await server.register([
{
plugin: require('inert')
},
{
plugin: require('spazy'),
options: {
folder: '.',
file: 'index.html'
}
}
]);
server.route([
{
method: 'GET',
path: '/nonspa/{path*}',
handler: {
spazy: {
spa: false
}
}
},
{
method: 'GET',
path: '/{path*}',
handler: async function (req, res) {
return res.spazy(req.url);
}
}
]);
await server.start();Options can be used for register, response.spazy, and handler.spazy. Options used in response and handler will overwrites the register options locally for that route. Also accepts options for Inert.
file: Stringthe default file to serve index.htmlfolder: Stringthe default folder to serve files .spa: Booleansingle page application mode default truetrailing: Booleanredirect trailing slash default falseredirects: Arraya list of redirects.redirect: Arrayfrom: Stringto: String
base: Stringwill change the base path for spa index.html file. Useful for serving content from non root path default /secure: Booleanredirect http to https default falseend: Inert Optionmode: Inert Optionstart: Inert OptionlookupMap: Inert OptionetagMethod: Inert OptionlookupCompressed: Inert Option
Transmits a file from the file system via a handler function. Returns a promise.
path: Stringthe file/folder path to serve requiredoptions: Objectsee above options
Transmits a file from the file system via a handler object.
path: Stringthe file/folder path to serve required*if path is an asterisk it will to serve the request.path
options: Objectsee above options
Why You Should Choose MPL-2.0 This project is licensed under the MPL-2.0 License