UNPKG

smc-hub

Version:

CoCalc: Backend webserver component

38 lines 1.8 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var cookies_1 = __importDefault(require("cookies")); var logger_1 = require("smc-hub/logger"); var COOKIE_OPTIONS = require("smc-hub/client").COOKIE_OPTIONS; // import { COOKIE_OPTIONS } from "smc-hub/client"; function init(router) { var winston = logger_1.getLogger("set-cookie"); router.get("/cookies", function (req, res) { if (req.query.set) { // TODO: implement setting maxAge as part of query? not needed for now. var 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 var cookies = new cookies_1.default(req, res, { secure: true }); var conf = __assign(__assign({}, COOKIE_OPTIONS), { maxAge: 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