UNPKG

@cocalc/hub

Version:
27 lines 1.4 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const cookies_1 = __importDefault(require("cookies")); const logger_1 = require("@cocalc/hub/logger"); const { COOKIE_OPTIONS } = require("@cocalc/hub/client"); // import { COOKIE_OPTIONS } from "@cocalc/hub/client"; function init(router) { const winston = (0, logger_1.getLogger)("set-cookie"); router.get("/cookies", (req, res) => { if (req.query.set) { // TODO: implement setting maxAge as part of query? not needed for now. const maxAge = 1000 * 24 * 3600 * 30 * 6; // 6 months -- long is fine now since we support "sign out everywhere" ? winston.debug(`${req.query.set}=${req.query.value}`); // The option { secure: true } is needed if SSL happens outside the hub; see // https://github.com/pillarjs/cookies/issues/51#issuecomment-568182639 const cookies = new cookies_1.default(req, res, { secure: true }); const conf = { ...COOKIE_OPTIONS, maxAge }; winston.debug(`conf=${JSON.stringify(conf)}`); cookies.set(req.query.set, req.query.value, conf); } res.end(); }); } exports.default = init; //# sourceMappingURL=set-cookies.js.map