Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Context

Hierarchy

  • Context

Indexable

[key: string]: any

Provided by custom middlewares

All middlewares (and routes) can edit the context, be carefull to not clash with other middlewares 😉

Index

Properties

Optional cookies

cookies: object

provided when

import {parseCookie} from 'u-http-server';

app.use(app.parseCookie);

app.get('/', ({cookies}) => cookies);

When you call it :

HTTP GET /
{}

// a json object with cookies info

params

params: object

params from url

example
app.get('/:username/:commentId', ({params}) => params))

When you call it :

HTTP GET /tpoisseau/1
{"username": "tpoisseau", "commentId": 1}

Type declaration

  • [key: string]: string

request

if init({protocol: 'http2'}) then Http2ServerRequest else IncomingMessage

response

if init({protocol: 'http2'}) then Http2ServerResponse else ServerResponse

Optional session

session: object

provided when

import {sessionInMemory} from 'u-http-server';

app.use(app.sessionInMemory);
app.use(ctx => ctx.session.lastVisitedUrl = app.address + ctx.request.url)

app.get('/session-info', ({session}) => session);

When you call it :

HTTP GET /
{"lastVisitedUrl": "http://localhost:3000/session-info"}

Generated using TypeDoc