You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

regex-router

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

regex-router

Route http(s) requests via regular expressions

2.0.0
latest
Source
npmnpm
Version published
Weekly downloads
2
-85.71%
Maintainers
1
Weekly downloads
 
Created
Source

Regex-router

npm version

Regex-router is a simple Node.js library to simplify web application routing without using a framework.

Example

var fs = require('fs');
var http = require('http');
var Router = require('regex-router');

var R = new Router(function(req, res, m) {
  res.end('404. URL not found: ' + req.url);
});

R.get(/^\/page\/(\w+)/, function(req, res, m) {
  console.log('Serving URL: %s', req.url);
  var page_name = m[1];
  var page_path = __dirname + '/static_pages/' + page_name + '.html';
  fs.readFile(page_path, 'utf8', function(err, html) {
    res.write(html);
    res.end();
  });
});

http.createServer(function(req, res) {
  R.route(req, res);
}).listen(80);

License

Copyright 2012-2015 Christopher Brown. MIT Licensed.

Keywords

http

FAQs

Package last updated on 27 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts