import { CookieHandler , UniversalCookies } from '../interfaces' ; import * as express from 'express' ; export class ExpressHandler implements CookieHandler { private req : express . Request ; private res : express . Response ; constructor ( req , res ) { this . req = req ; this . res = res ; } get ( key ) { if ( this . req . cookies . hasOwnProperty ( key ) ) { return this . req . cookies [ key ] ; } else { return undefined ; } } set ( key , value , options ) { const filled = { ... UniversalCookies . Options . DEFAULT , ... options } ; this . res . cookie ( key , value , ( { expires : filled . expires , path : filled . path , domain : filled . domain , secure : filled . secure , } as express . CookieOptions ) ) ; } remove ( key , options ) { const filled = { ... UniversalCookies . Options . DEFAULT , ... options } ; this . res . clearCookie ( key , ( { expires : filled . expires , path : filled . path , domain : filled . domain , secure : filled . secure , } as express . CookieOptions ) ) ; } }