All Projects → trailsjs → trailpack-hapi

trailsjs / trailpack-hapi

Licence: MIT license
📦 Hapi.js Trailpack

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to trailpack-hapi

trailmix
🍬 UI for generating a custom build using trailpacks
Stars: ✭ 12 (-36.84%)
Mutual labels:  trails, trailpack
trailpack-express
📦 Express Trailpack
Stars: ✭ 13 (-31.58%)
Mutual labels:  trails, trailpack
Thin
A very fast & simple Ruby web server
Stars: ✭ 2,170 (+11321.05%)
Mutual labels:  web-server
denoliver
A simple, dependency free static file server for Deno with possibly the worst name ever.
Stars: ✭ 94 (+394.74%)
Mutual labels:  web-server
Mongols
C++ high performance networking with TCP/UDP/RESP/HTTP/WebSocket protocols
Stars: ✭ 250 (+1215.79%)
Mutual labels:  web-server
Mojo
✨ Mojolicious - Perl real-time web framework
Stars: ✭ 2,298 (+11994.74%)
Mutual labels:  web-server
M-Volunteer-SpringBoot
美志愿APP服务端,客户端在https://github.com/learner1999/M-Volunteer
Stars: ✭ 52 (+173.68%)
Mutual labels:  web-server
Diamond
Diamond is a full-stack web-framework written in The D Programming Language using vibe.d
Stars: ✭ 173 (+810.53%)
Mutual labels:  web-server
tipi
Tipi - the All-in-one Web Server for Ruby Apps
Stars: ✭ 214 (+1026.32%)
Mutual labels:  web-server
Andserver
🍒 Web server and web framework of Android platform.
Stars: ✭ 2,932 (+15331.58%)
Mutual labels:  web-server
Kvantum
An intellectual (HTTP/HTTPS) web server with support for server side templating (Crush, Apache Velocity and JTwig)
Stars: ✭ 17 (-10.53%)
Mutual labels:  web-server
Servr
A simple HTTP server in R
Stars: ✭ 228 (+1100%)
Mutual labels:  web-server
Python Socketio
Python Socket.IO server and client
Stars: ✭ 2,655 (+13873.68%)
Mutual labels:  web-server
smurf
simple markdown surfer
Stars: ✭ 38 (+100%)
Mutual labels:  web-server
Catacumba
Asynchronous web toolkit for clojure built on top of Ratpack / Netty
Stars: ✭ 192 (+910.53%)
Mutual labels:  web-server
sapper-authentication-demo
A demonstration of Auth with Sapper + JWT + Server Side Rendering + RBAC
Stars: ✭ 102 (+436.84%)
Mutual labels:  hapi
Aero
🚄 Fastest node.js framework. Go version is actively maintained: @aerogo
Stars: ✭ 181 (+852.63%)
Mutual labels:  web-server
Sanic
Async Python 3.7+ web server/framework | Build fast. Run fast.
Stars: ✭ 15,660 (+82321.05%)
Mutual labels:  web-server
hapi-docs
Beautiful API documentation generator for Hapi using Vue
Stars: ✭ 64 (+236.84%)
Mutual labels:  hapi
hapi-plugin-mysql
Hapi plugin for MySQL
Stars: ✭ 17 (-10.53%)
Mutual labels:  hapi

trailpack-hapi

Gitter NPM version Build status Dependency Status Code Climate

Hapi Trailpack. This pack binds the routes compiled in trailpack-router to a Hapi Server.

Usage

Load in your trailpack config.

// config/main.js
module.exports = {
  // ...
  packs: [
    require('trailpack-core'),
    require('trailpack-router'),
    require('trailpack-hapi')
  ]
}

View Config

Choose a template engine.

// config/views.js
module.exports = {
  engine: 'handlebars'
}

Then simply write your views in a directory called 'templates'! This feature has been tested with Jade and Handlebars.

Configuration

See config/web.js for an example.

port

The port to listen on. 3000 by default. Can also be set via the PORT environment variable.

Server configuration

Configure your Hapi.Server by adding options property to the web.js config in typical Hapi.server format. See: http://hapijs.com/api#new-serveroptions

// config/web.js
module.exports = {
  options: {

    routes: {
      cors: true
    }
  }
}

Hapi Plugins

Register your hapi plugins by adding them to the config/web.js config in typical Hapi plugin format. See: http://hapijs.com/tutorials/plugins#loading-a-plugin

// config/web.js
module.exports = {
  plugins: [
    {
      register: require('vision'),
      options: { }
    },
    {
      register: require('inert'),
      options: { }
    },
    {
      register: require('hapi-auth-hawk'),
      options: { }
    }
    // ...
  ],

  onPluginsLoaded: function (err) {
    // Note that `this` is Trails `app` instance
    this.packs.hapi.server.auth.strategy('default', 'hawk', { getCredentialsFunc: getCredentials });
  }
}

Hapi Views

// config/web.js
module.exports = {
  views: {
    engines: {
      html: require('some-view-engine')
    },
    path: 'views'
  }
}

Static Assets

// config/main.js
module.exports = {
  paths: {
    ...
    www: path.resolve(__dirname, '..', 'static')
    ...
  }
}

This allows static files such as js or images to be served in the /static directory. If you prefer, feel free to use a name other than 'static'!

Multiple Static Assets

// config/main.js
module.exports = {
  paths: {
    ...
    www: [
      {
        path: path.resolve(__dirname, '..', 'static'),
        humanUrl: '/admin'
      },
      {
        path: path.resolve(__dirname, '..', 'uploads', 'pictures', 'cats'),
        humanUrl: '/cats'
      }
    ]
    ...
  }
}

Also you can make multiple static assets with human url. For example your static files in /uploads/pictures/cats with humanUrl you url look like http://example.com/cats humanUrl - not require

Contributing

We love contributions! Please check out our Contributor's Guide for more information on how our projects are organized and how to get started.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].