• This repository has been archived on 13/Feb/2019
  • Stars
    star
    340
  • Rank 120,393 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 11 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Express / Connect middleware for websites. Goes well with HTML5 Boilerplate.

h5bp Build Status


⚠️ This module is depecrated (Express 3.x) and is being rewritten.


HTML5 boilerplate (H5BP) server config for node.js.

h5bp for node.js follows the guidelines of the Apache version:

  • secures backup and hidden files.
  • optionally redirects www.yoursite.tld to yoursite.tld or vice versa.
  • offers a simple cache busting mechanism.
  • normalize content types.
  • optionally enables CORS.
  • sets correct cache expires depending of the type of resource.
  • and some others...

It also focuses on offering additional features such as on-the-fly script concatenation using CommonJS or AMD.

Installation

npm install --save h5bp

Quick Start

Create a simple http server

var h5bp = require('h5bp');

var app = h5bp.createServer({ root: __dirname + '/public' });
app.listen(3000);

app is an instance of an express application. You can add additional middlewares or routes if you like.

Use it as a connect / express middleware

var express = require('express'),
    h5bp = require('h5bp');

var app = express();
app.use(h5bp({ root: __dirname + '/public' }));

// in order to serve files, you should add the two following middlewares
app.use(express.compress());
app.use(express.static(__dirname + '/public'));
app.listen(3000);

Concatenate scripts on-the-fly

If you want to split your application source files but only serve one file, you can use the on-the-fly concatenation. If you are familiar with node.js, you can use the CommonJS style. You can also use the AMD style.

app.use(h5bp({
    root: __dirname + '/public',
    scripts: {
        files: ['app.js'],
        processor: 'commonjs'   // can also be "amd"
    }
}));

At the first request hit to /app.js, the server will compile, cache and serve the file. Any subsequent request will serve the cached file without any performance impact.

So, this feature is meant to be used with the cache busting mechanism in order to ensure the client always has the latest resource version. If you restart your server, the cache will be flushed.

Note that the next release will provide a development mode where the server will simply disable its cache and always serve the latest version of the file.

Options

There are several options you can pass to the middleware.

app.use(h5bp(options));

root

Tells the filesystem path to the root directory of static resources. This options is mandatory if you serve static files.

www

Forces www if true, forces non-www if false, does nothing if not defined. By default, this is disabled.

cors

Enables CORS for everything. By default this is disabled.

dotfiles

Enables access to dotfiles. By default this is disabled.

scripts

Tells which scripts to concatenate.

This is an object with the following properties:

files

This is an array of files to concatenate. Their path is relative to the root option. Their URL will be absolute.

For example, if you set files to ['scripts/app.js'] and root to /home/h5bp/app/:

  • The path will be: /home/h5bp/app/scripts/app.js.
  • The served URL will be: yoursite.tld/scripts/app.js.

processor

Tells which processor to use for scripts concatenation.

For now, it can be one of the following values:

  • commonjs: will concatenate files using the CommonJS method (require/exports).
  • amd: will concatenate files using the AMD method (require/define).

Additional options

The h5bp.createServer function takes the same options, plus additional ones.

The callback is optional. It is a custom middleware that you can register directly if you want to.

h5bp.createServer(options, [callback]);

server

Tells which type of server you want to use.

It can be one of the following values:

  • express: uses express, this is the default value.
  • connect: uses connect.

logger

Tells if you want to log server requests or not. This can also be an object containing logger options.

compress

Tells if you want to serve gzipped content or not. By default this is true.

If you are using h5bp as a middleware, we strongly encourage you to use the compress middleware provided by express / connect.

License

MIT License

More Repositories

1

Front-end-Developer-Interview-Questions

A list of helpful front-end related questions you can use to interview potential candidates, test yourself or completely ignore.
Nunjucks
58,638
star
2

html5-boilerplate

A professional front-end template for building fast, robust, and adaptable web apps or sites.
JavaScript
55,802
star
3

server-configs-nginx

Nginx HTTP server boilerplate configs
10,923
star
4

Effeckt.css

This repo is archived. Thanks!
CSS
10,917
star
5

mobile-boilerplate

DEPRECATED - A front-end template that helps you build fast, modern mobile web apps.
ApacheConf
3,864
star
6

server-configs-apache

Apache HTTP server boilerplate configs
Shell
3,161
star
7

server-configs

Boilerplate configurations for various web servers.
3,090
star
8

lazyweb-requests

Get projects and ideas built by the community
1,687
star
9

ant-build-script

Ant build script intended for use with HTML5 Boilerplate. You may find something useful here, but this project is archived.
Shell
984
star
10

html5please

Graded Feature Support: Look up web technologies and find out if they are ready for use.
JavaScript
836
star
11

html5boilerplate.com

Files for the HTML5 Boilerplate website.
HTML
483
star
12

mothereffinganimatedgif

Make your animated gifs in the browser! Oh yeah!
JavaScript
377
star
13

server-configs-iis

IIS Web.Config Boilerplates
340
star
14

movethewebforward

Project archived.
JavaScript
283
star
15

create-html5-boilerplate

npx quick start for html5-boilerplate
JavaScript
277
star
16

generator-h5bp

Archived!
JavaScript
240
star
17

main.css

A repository for the development of the HTML5 Boilerplate CSS file, main.css
CSS
191
star
18

generator-server-configs

This project is archived
JavaScript
137
star
19

html5-boilerplate-template

HTML5-Boilerplate Template Repo
CSS
88
star
20

h5bp.github.io

A website for the H5BP organization. Browse all the H5BP projects in one place.
JavaScript
84
star
21

generator-mobile-boilerplate

Scaffolds out H5BP Mobile Boilerplate
JavaScript
76
star
22

server-configs-gae

Google App Engine (GAE) app boilerplate config
62
star
23

server-configs-lighttpd

Lighttpd HTTP server boilerplate configs
54
star
24

html5boilerplate.com-mobile

Deprecated- thanks!
JavaScript
40
star
25

server-configs-test

Tests for HTTP server boilerplate configs
JavaScript
36
star
26

.github

The readme for the @h5bp organization's homepage
4
star