0.0.1 • Published 11 months ago

passer v0.0.1

Weekly downloads
2
License
MIT
Repository
-
Last release
11 months ago

A simple NodeJS server request manager

NPM stats

Known Vulnerabilities

Setup

var passer = require('passer');

var serverToPipeForSockets = passer.listen(8080);

Request Management

Supported Methods:

  • Get
  • Post
  • Put
  • Delete
  • Patch
  • Custom

All bindings allow for wildcard characters for instance; Request /user/36Ab9z-cat/profilePic will activate /user/*/profilePic * represents any number of any characters Note items binded before others will have higher priority. Wildcards can be accessed in req.wildcards.

On Request Get

passer.get('/test', function(req, res){
  res.write('HELLO WORLD!!!\n');
  res.write('Session ID:'+req.session.id+'\n');
  res.end('END');
});

Request Post

Currently Supports:

  • Standard Post (www form urlencoded)
  • Multipart Form-data
  • JSON
passer.post('/someURL', function(req,res){
  req.form.on('field', function(feildname, info, data){
    //Received some data for a field
  });
  req.forms.on('end', function(){
    //All data for the field has been received
  });
  req.forms.on('finish', function(){
    //All data for, form has been received
  });
});

Custom

passer.bind(method[String], path[String], callback[Function], requirements[Object])

Public Files

If you set a value for publicFolder then on request if there is no handler mapped to that url then it will try and serve a file from set folder before responding with error 404

  passer.publicFolder = "public";

404

This is the default value, but can be changed

passer.on404 = function(req, res){
  res.statusCode = 404;
  res.end("Cannot find "+req.url);
}

HTML header file

If you defined a header file then it will auto merge the body, and header of a html file. If query key "?noHeader" is in the request url then it will just serve the html file without the header file.

passer.headerFile = "./public/header.html";

Client Data

Sessions

passer.noSession = false; //Default: false

passer.get('/', function(req, res){
  var sessionInfo = req.session; //User's session data

  if (!sessionInfo.someTagName){ //If defined
    res.end('You have been here before and had your someTagName set to:'+sessionInfo.someTagName);
  }else{
    res.end('FIRST TIME!');
  }

  sessionInfo.someTagName = "value";
});

Session Expiry

The length of time it takes for a session to expire it defined via.

passer.sessionExpiry = 3*60*60*1000 //3hrs in ms, this is the default value

Disable Sessions

passer.noSession = true;

Cookies

  passer.get('/',function(req,res){
    console.log(req.cookies);
  });

Query Items

  passer.get('/',function(req,res){
    console.log(req.query);
  });

Path

passer.get('/', function(req, res){
  console.log('Path no queries: '+req.path);
  console.log('Path with queries:'+req.url);
});

Authorization

addAuth(pathsInZoneArray String, testerfunction, onFailTestfunction, ignorePathsArray String);

  passer.addAuth(['*'], function(req){
    return req.session.loggedIn;
  }, function(req, res){
    res.writeHead(401);
    res.end('Invalid connection');
  }, ['/login']);

Document MimeTypes

Within passer you can use it as a shortcut to be able to get any mime type based of a file extention.

console.log(passer.documentTypes['mp3']); //will log out: audio/mpeg3
0.0.1

11 months ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.5

5 years ago

2.1.4

5 years ago

2.1.3

5 years ago

2.1.2

8 years ago

2.1.1

8 years ago

2.1.0

8 years ago

2.0.3

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.3.0

8 years ago

1.2.19

8 years ago

1.2.18

8 years ago

1.2.17

8 years ago

1.2.16

8 years ago

1.2.15

9 years ago

1.2.14

9 years ago

1.2.13

9 years ago

1.2.12

9 years ago

1.2.11

9 years ago

1.2.10

9 years ago

1.2.9

9 years ago

1.2.8

9 years ago

1.2.7

9 years ago

1.2.6

9 years ago

1.2.5

9 years ago

1.2.4

9 years ago

1.2.3

9 years ago

1.2.2

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago