# fooler-session

> redis session for fooler

Latest version **1.0.1** (published 2021-07-15) · ISC license · 0 weekly downloads

## Install

```sh
npm install fooler-session
pnpm add fooler-session
yarn add fooler-session
bun add fooler-session
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2021-07-15 |
| First published | 2020-12-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 12.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | NBye |
| Maintainers | nbye |
| Keywords | fooler, session |

## Links

- npm: https://www.npmjs.com/package/fooler-session
- Repository: https://github.com/NBye/fooler-session
- Homepage: https://github.com/NBye/fooler-session#readme
- Issues: https://github.com/NBye/fooler-session/issues
- npm.io page: https://npm.io/package/fooler-session

## Dependencies (1)

- [fooler-redis](https://npm.io/package/fooler-redis.md) ^1.0.0

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2021-07-15
- 1.0.0 — 2020-12-08

## README

# fooler-session
1. fooler-session 是一 fooler-core 框架 的session 支持;

### 一、安装使用
1. npm install fooler-session
2. 设置启动配置 session 的 redis 链接配置
3. 路由使用 这个组件

### 二、示例1 在指定路由设置使用session
```javascript
const { Fooler } = require('fooler-core');
const Session = require('fooler-session');
const app = Fooler.create({
    p: 8080,
    processes: 1,

    "session": {            //这个配置时必须的
        "port": 6379,
        "host": "127.1.0.1",
        "options": {}       //如果设置密码 options的值 {"password": "123456","db": 0}
    }
});
app.route.GET(/^.*/)
    .then(Session)          //在置顶路由中使用
    .then(async ({ ctx }) => {
        let data = await ctx.session.get();
        ctx.session.set('times', (data.times || 0) + 1);
        ctx.sendJSON(data)
    });
app.run();
```

### 三、全局设置 session

```javascript
const { Fooler } = require('fooler-core');
const Session = require('fooler-session');
const app = Fooler.create({
    p: 8080,
    processes: 1,

    "session": {            //这个配置时必须的
        "port": 6379,
        "host": "127.1.0.1",
        "options": {}       //如果设置密码 options的值 {"password": "123456","db": 0}
    }
});
app.route.then(Session);    //在顶级路由中设置session
app.route.GET(/^.*/)
    .then(async ({ ctx }) => {
        let data = await ctx.session.get();
        ctx.session.set('times', (data.times || 0) + 1);
        ctx.sendJSON(data)
    });
app.run();
```


### 三、给指定路由组 session

```javascript
const { Fooler } = require('fooler-core');
const Session = require('fooler-session');
const app = Fooler.create({
    p: 8080,
    processes: 1,

    "session": {        //这个配置时必须的
        "port": 6379,
        "host": "127.1.0.1",
        "options": {}   //如果设置密码 options的值 {"password": "123456","db": 0}
    }
});
app.route.when('/my')
    .then(Session)      //给指定路由组 session
    .childen((r)=>{
        r.when('/book/add').then(async ({ ctx }) => {
            let data = await ctx.session.get();
            ctx.session.set('times', (data.times || 0) + 1);
            ctx.sendJSON(data)
        }
        r.when('/book/rem').then(async ({ ctx }) => {
            let data = await ctx.session.get();
            ctx.session.set('times', (data.times || 0) + 1);
            ctx.sendJSON(data)
        }
    });
app.run();
```

---
_Source: https://npm.io/package/fooler-session · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
