UNPKG

@creamapi/cream

Version:

Concise REST API Maker - An extension library for express to create REST APIs faster

25 lines (24 loc) 1.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SetCookie = SetCookie; const __1 = require("../.."); const Header_1 = require("../Headers/Header"); /** * This method is used to statically set a value of a cookie in the response * @param cookieName the cookie name * @param coookieValue the value associated with the cookie * @param cookieOpt the options for the cookie * @returns the decorator function for the class with the correct information */ function SetCookie(cookieName, coookieValue, cookieOpt) { return function (target) { let headers = Reflect.getMetadata(Header_1.HTTP_HEADERS_METADATA_KEY, target.prototype) || new Map(); let newHeaderBuilder = headers.get('Set-Cookie') || new __1.ResponseCookieManager(); newHeaderBuilder.push(__1.Cookie.fromCookieOpts(cookieName, coookieValue, cookieOpt)); headers.set('Set-Cookie', newHeaderBuilder); Reflect.defineMetadata(Header_1.HTTP_HEADERS_METADATA_KEY, headers, target.prototype); return target; }; }