🚀 Socket Launch Week 🚀 Day 4: Introducing Historical Analytics.Learn More
Socket
Sign inDemoInstall
Socket

@candyjs/session-cookie

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@candyjs/session-cookie

基于 cookie 的 session

0.0.2
latest
npm
Version published
Maintainers
1
Created
Source

基于 cookie 的 session

安装

$ npm install @candyjs/session-cookie

使用

入口文件配置

// index.js
const CandyJs = require('candyjs');
const App = require('candyjs/web/Application');
const Hook = require('candyjs/core/Hook');
const Session = require('@candyjs/session-cookie');

Hook.addHook(Session.start({
    key: 'some secure strings',
    // 毫秒
    maxAge: 86400000
}));

new CandyJs(new App({
    'id': 1,
    'debug': true,
    'appPath': __dirname + '/app'

})).listen(2333, function(){
    console.log('listen on 2333');
});

使用

// IndexController.js
const Controller = require('candyjs/web/Controller');

class IndexController extends Controller {

    run(req, res) {
        let views = req.session.getAttribute('views');

        if(undefined === views) {
            views = 0;
        } else {
            views += 1;
        }

        req.session.setAttribute('views', views);

        res.write('views: ' + views);
        res.end();
    }

}

API

session#getAttribute(name: string): any;
session#setAttribute(name: string, value: any): void;
session#deleteAttribute(name: string): void;
session#clear(): void;

FAQs

Package last updated on 01 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts