Browse Source

initial commit

master v0.1.0
Brett Langdon 12 years ago
commit
05c814810c
5 changed files with 116 additions and 0 deletions
  1. +1
    -0
      .gitignore
  2. +4
    -0
      Makefile
  3. +70
    -0
      README.md
  4. +15
    -0
      index.js
  5. +26
    -0
      package.json

+ 1
- 0
.gitignore View File

@ -0,0 +1 @@
node_modules

+ 4
- 0
Makefile View File

@ -0,0 +1,4 @@
test:
@echo "No Tests"
.PHONY: test

+ 70
- 0
README.md View File

@ -0,0 +1,70 @@
YAPS Cookies
============
[![NPM version](https://badge.fury.io/js/yaps-cookies.png)](http://badge.fury.io/js/yaps-cookies)
This is a cookie plugin for [YAPS](https://github.com/brettlangdon/yaps.git).
It simply uses [node-cookie](https://github.com/shtylman/node-cookie) under the hood to parse and set cookie headers.
## Installation
### Via NPM
```bash
npm install [-g] yaps-cookies
```
### Via Git
```bash
git clone git://github.com/brettlangdon/yaps-cookies.git
cd ./yaps-cookies.git
npm install
```
## Usage
```javascript
var yaps = require("yaps");
var yaps_cookies = require("yaps-cookies");
var app = new yaps.server();
app.registerPlugin(yaps_cookies);
var my_plugin = function(options){
this.GET("/", function(request, server, respond){
// this is an object of the cookies sent with the request
// {"name": "value"}
console.dir(request.cookies);
// add a response cookie
request.setCookie("user-id", "some value");
respond(200, "thanks");
});
};
app.registerPlugin(my_plugin);
app.start();
```
## License
```
The MIT License (MIT)
Copyright (c) 2013 Brett Langdon <brett@blangdon.com> (http://www.brett.is)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
```

+ 15
- 0
index.js View File

@ -0,0 +1,15 @@
var cookie = require("cookie");
var yaps_cookies = function(options){
this.on("setup", this.on_setup);
};
yaps_cookies.prototype.on_setup = function(request, server, done){
request.setCookie = function(name, value, options){
request.addHeader("Set-Cookie", cookie.serialize(name, value, options));
};
request.cookies = cookie.parse(request.headers.cookie || "");
done();
};
module.exports = yaps_cookies;

+ 26
- 0
package.json View File

@ -0,0 +1,26 @@
{
"author": "Brett Langdon <brett@blangdon.com> (http://brett.is)",
"bugs": {
"url": "https://github.com/brettlangdon/yaps-cookies/issues"
},
"dependencies": {
"cookie": "~0.1.0"
},
"description": "Cookie management plugin for YAPS",
"keywords": [
"yaps",
"http",
"cookie"
],
"license": "MIT",
"main": "index.js",
"name": "yaps-cookies",
"repository": {
"type": "git",
"url": "git://github.com/brettlangdon/yaps-cookies.git"
},
"scripts": {
"test": "make test"
},
"version": "0.1.0"
}

Loading…
Cancel
Save