RingoJS

Module middleware/cookies

This module provides middleware for reading cookies from the request. It does not provide any functions to set cookies in the response.

Example

const {Application} = require("stick");
const {setCookie} = require("ringo/utils/http");
const response = require("ringo/jsgi/response");
const app = exports.app = new Application();
app.configure("cookies", "route");

app.get("/setCookies", function(req) {
  // ringo/utils/http is used to set cookies
  return response.addHeaders({
    "set-cookie": [
      setCookie("test1", "value1", 1),
      setCookie("test2", "value2", 1)
    ]
  }).text("Done.");
});

app.get("/getCookies", function(req) {
  // req.cookies is provided by this middleware
  // result will be:
  // {
  //   "test1": "value1",
  //   "test2": "value2"
  // }
  return response.json(req.cookies);
});

Functions

Properties


middleware (next, app)

This middleware provides support for cookie access.

Parameters

Function next

the wrapped middleware chain

Object app

the Stick Application object

Returns

Function

a JSGI middleware function


request.cookies

A cookies object for the current request.