h5bp / server-configs-node

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Umm... how do I use this?

dstroot opened this issue · comments

Was expecting to see something like "app.js" in the root directory calling /lib/h5bp.js. But with no example code/app and no documentation I'm puzzled how I can get the value out of what is obviously a lot of thought and expertise backed into h5BP.js.

You're right, documentation is still missing for usage... I will update the readme with some basic examples asap.

To sum up, h5bp.js is for node.js what h5bp .htaccess is for Apache, a server configuration boilerplate which tries to apply a collection of best practices for serving websites.
The usage is meant to be as simple as possible.

You can use it to create a server:

var h5bp = require('h5bp');

var app = h5bp.createServer({ root: __dirname + '/public' });
// by default app is an express server

Or use it as a connect / express middleware:

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

Like the htaccess version, the code of h5bp.js is meant to be self explanatory and pretty well documented. I invite you to read it for more details.

Thanks!

This works but I have no idea if I'm really thinking about this right.
Express 3 is no longer an http server but its confusing to have two
.createServer calls.

/* ==============================================================
Dependencies
=============================================================== */
var h5bp = require('./lib/h5bp')
, http = require('http');

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

/* ==============================================================
Configuration
=============================================================== */
app.configure(function(){
app.set('port', process.env.PORT || 8080);
});

var server = http.createServer(app).listen(app.get('port'), function(){
console.log("H5bp server listening on port %d", app.get('port'));
});

On Thu, Feb 14, 2013 at 1:48 PM, Nicolas Gryman notifications@github.comwrote:

You're right, documentation is still missing for usage... I will update
the readme with some basic examples asap.

To sum up, h5bp.js is for node.js what h5bp .htaccess is for Apache, a
server configuration boilerplate which tries to apply a collection of best
practices for serving websites.
The usage is meant to be as simple as possible.

You can use it to create a server:

var h5bp = require('h5bp');
var app = h5bp.createServer({ root: __dirname + '/public' });// by default app is an express server

Or use it as a connect / express middleware:

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

Like the htaccess version, the code of h5bp.js is meant to be self
explanatory and pretty well documented. I invite you to read it for more
details.


Reply to this email directly or view it on GitHubhttps://github.com//issues/5#issuecomment-13580599.

  • Dan Stroot

express is a server, the api has slightly changed in 3.x from express.createServer to express(). You can still use express.createServer, but it is obsolete (https://github.com/visionmedia/express/blob/master/lib/express.js#L63).

Using express, you don't really need node's http module as it is already wrapped by express.

h5bp.createServer is just another handy wrapper of express(), adding some defaults / h5bp middlewares to the stack.

You should first install h5bp with npm install h5bp to grab all dependencies and require it correctly.

Your code should look like this:

var h5bp = require('h5bp');

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

/* ==============================================================
    Configuration
=============================================================== */
app.configure(function(){
  app.set('port', process.env.PORT || 8080);
});

app.listen(app.get('port'), function(){
  console.log("H5bp server listening on port %d", app.get('port'));
});

Closing this issue as I have updated the docs. If you have other questions you can post them here :)

Thanks!