GithubHelp home page GithubHelp logo

xeaone / spazy Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 1.0 60 KB

Static single page application and handlers for hapi.js

License: Mozilla Public License 2.0

JavaScript 92.60% CSS 0.44% HTML 6.96%
hapi hapijs static spa inert

spazy's Introduction

Spazy

Static and single page application plugin for hapi.js. Spazy uses the tried and true inert to handle the file serving.

Install

npm i spazy --save

Requirements

  • hapi v18.X.X
  • inert v5.X.X

Example

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();

API

options

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: String the default file to serve index.html
  • folder: String the default folder to serve files .
  • spa: Boolean single page application mode default true
  • trailing: Boolean redirect trailing slash default false
  • redirects: Array a list of redirects.
    • redirect: Array
      • from: String
      • to: String
  • base: String will change the base path for spa index.html file. Useful for serving content from non root path default /
  • secure: Boolean redirect http to https default false
  • end: Inert Option
  • mode: Inert Option
  • start: Inert Option
  • lookupMap: Inert Option
  • etagMethod: Inert Option
  • lookupCompressed: Inert Option

response.spazy(path, [options])

Transmits a file from the file system via a handler function. Returns a promise.

  • path: String the file/folder path to serve required
  • options: Object see above options

handler.spazy

Transmits a file from the file system via a handler object.

  • path: String the file/folder path to serve required
    • * if path is an asterisk it will to serve the request.path
  • options: Object see above options

Authors

Alexander Elias

License

Why You Should Choose MPL-2.0 This project is licensed under the MPL-2.0 License

spazy's People

Contributors

dependabot[bot] avatar xeaone avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

lgtm-migrator

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.