web-site

0.51.0 • Public • Published

web-site is a wrapper for Express that adds the things it boneheadedly leaves out by default:

var WebSite = require("web-site")
 
var site = new WebSite()
site.addRoute("get", "/", function(request,response) {
  response.send("okay")
})
site.start(4100)
site.stop()

Why

In the name of modularity, Express has stopped doing basic web server things by default. Like stopping. Or parsing form data. Or handling AJAX requests. These things are the most basic, fundamental activities of a web server, it's OK to load them by default.

Features

  • Parses submitted forms by default
  • Parses JSON forms by default
  • Parses cookies by default
  • site.stop()
  • site.isStarted()
  • site.getPort()

BYOHS (Bring Your Own HTTP Server)

If you want to tell the web site to use a different http server, you can ask it to relinquish control of starting and stopping:

var site = new WebSite()
site.addRoute(...)
 
site.relinquishControl(function() {
  var httpServer = ...
 
  // we can start this here, or wait, or whatever
 
  // Then we return the httpServer so the routes can go into that instead:
  return httpServer
}

See get-socket for an example.

sendFile

A method for static files is included just so you don't have to include the path module:

site.addRoute(
  "/some-script.js",
  site.sendFile(__dirname, "path/to/your/jazz.js")
)

Probably a better idea than opening up a whole static folder that could be full of anything.

Readme

Keywords

none

Package Sidebar

Install

npm i web-site

Weekly Downloads

2

Version

0.51.0

License

ISC

Unpacked Size

8.46 kB

Total Files

4

Last publish

Collaborators

  • erikpukinskis