{"id":20504502,"url":"https://github.com/candyframework/candyjs-session-cookie","last_synced_at":"2026-06-06T10:32:08.137Z","repository":{"id":57681642,"uuid":"491493664","full_name":"candyframework/candyjs-session-cookie","owner":"candyframework","description":null,"archived":false,"fork":false,"pushed_at":"2022-06-01T01:40:44.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-02T00:03:55.470Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/candyframework.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-12T11:54:44.000Z","updated_at":"2022-05-12T11:56:29.000Z","dependencies_parsed_at":"2022-09-03T19:50:29.072Z","dependency_job_id":null,"html_url":"https://github.com/candyframework/candyjs-session-cookie","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/candyframework%2Fcandyjs-session-cookie","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/candyframework%2Fcandyjs-session-cookie/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/candyframework%2Fcandyjs-session-cookie/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/candyframework%2Fcandyjs-session-cookie/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/candyframework","download_url":"https://codeload.github.com/candyframework/candyjs-session-cookie/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242102027,"owners_count":20071992,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T19:38:27.020Z","updated_at":"2025-03-05T20:50:11.269Z","avatar_url":"https://github.com/candyframework.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# candyjs-session-cookie\n\n基于 cookie 的 session\n\n## 安装\n\n```\n$ npm install @candyjs/session-cookie\n```\n\n## 使用\n\n入口文件配置\n\n```\n// index.js\nconst CandyJs = require('candyjs');\nconst App = require('candyjs/web/Application');\nconst Hook = require('candyjs/core/Hook');\nconst Session = require('@candyjs/session-cookie');\n\nHook.addHook(Session.start({\n    key: 'some secure strings',\n    // 毫秒\n    maxAge: 86400000\n}));\n\nnew CandyJs(new App({\n    'id': 1,\n    'debug': true,\n    'appPath': __dirname + '/app'\n\n})).listen(2333, function(){\n    console.log('listen on 2333');\n});\n```\n\n使用\n\n```\n// IndexController.js\nconst Controller = require('candyjs/web/Controller');\n\nclass IndexController extends Controller {\n\n    run(req, res) {\n        let views = req.session.getAttribute('views');\n\n        if(undefined === views) {\n            views = 0;\n        } else {\n            views += 1;\n        }\n\n        req.session.setAttribute('views', views);\n\n        res.write('views: ' + views);\n        res.end();\n    }\n\n}\n```\n\n## API\n\n```\nsession#getAttribute(name: string): any;\nsession#setAttribute(name: string, value: any): void;\nsession#deleteAttribute(name: string): void;\nsession#clear(): void;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcandyframework%2Fcandyjs-session-cookie","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcandyframework%2Fcandyjs-session-cookie","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcandyframework%2Fcandyjs-session-cookie/lists"}