connect-simple

0.0.5 • Public • Published

A simple connect middleware for rapidly creating pages

Install

npm install connect connect-simple

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'];
this.res.end(ua);

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

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

In some cases, there may be things that you will need access to in all your pages (for example, underscore), you can do this by importing them:

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

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

In this example, you will be able to access underscore from within your pages: this._

Todo List

  • Watch for files that have changed and then update the cache
  • Logging

Readme

Keywords

none

Package Sidebar

Install

npm i connect-simple

Weekly Downloads

6

Version

0.0.5

License

BSD

Last publish

Collaborators

  • saralk