An extremely simple router/framework middleware for node connect
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

A simple connect middleware for rapidly creating pages


npm install connect connect-simple

Basic Usage

Use the connect middleware like so...

var connect = require('connect');
var simple = require('connect-simple');

var app = connect().use(new simple({root: './www'})).listen(3000);

In your app's root directory, create the file ./www/index.js

var ua = this.req.headers['user-agent'];

Start your app, and go to http://localhost:3000, you should see your browser's user agent

Creating Pages

You can add js files to the /www folder and you will be able to access them in your browser, for example http://localhost:3000/test will resolve to ./www/test.js

The contents of the JavaScript files will be evaluated in a function, from within a SimpleObject

The variable this.req will refer to the node.js request object.

There will also be a variable called this.res which will refer to the node.js response object.

Importing External Libraries

You can import external libraries which will be acccesible from within all your pages, in this example, we will import underscore:

var connect = require('connect');
var simple = require('connect-simple');
var underscore = require('underscore');

var app = connect()
            .use(new simple({
                root: './www',
                imports: {
                    '_' : underscore

Now, in your JavaScript files, underscore will be prototyped on to the SimpleObject, so from within your pages, you can access it with this._

Todo List

  • Watch for files that have changed and then update the cache
  • Logging
  • URL Rewriter (simiar to .htaccess)