如果您没有在项目中使用Babel,没有Babel你也可以试试这个版本。
koa-session2
Middleware for Koa2 to get/set session use with custom stores such as Redis or mongodb with Babel
koa-session2
Middleware for Koa2 to get/set session use with custom stores such as Redis or mongodb with Babel
If you are not using babel in your projects, maybe you can try this version without babel.
Installnpm install koa-session2
Usageimport Koa from "koa";<br>
import session from "koa-session2";<br>
<br>
const app = new Koa();<br>
<br>
app.use(session({<br>
key: "SESSIONID", //default "koa:sess" <br>
}));
Custom Stores
Store.jsimport Redis from "ioredis";<br>
import {Store} from "koa-session2";<br>
<br>
export default class RedisStore extends Store {<br>
constructor() {<br>
super();<br>
this.redis = new Redis();<br>
}<br>
<br>
async get(sid) {<br>
return await this.redis.get(`SESSION:${sid}`);<br>
}<br>
<br>
async set(session, opts) {<br>
if(!opts.sid) {<br>
opts.sid = this.getID(24);<br>
}<br>
await this.redis.set(`SESSION:${opts.sid}`, session);<br>
return opts.sid;<br>
}<br>
<br>
async destroy(sid) {<br>
return await this.redis.del(`SESSION:${sid}`);<br>
}<br>
}
main.jsimport Koa from "koa";<br>
import session from "koa-session2";<br>
import Store from "./Store.js";<br>
<br>
const app = new Koa();<br>
<br>
app.use(session({<br>
store: new Store()<br>
}));<br>
<br>
app.use(ctx => {<br>
let user = ctx.session.user;<br>
<br>
ctx.session.view = "index";<br>
});
Options
Most options based on cookieskey: a string for store session id in cookie<br>
<br>
store: a class for custom store (extend {Store}, func: #get(sid), #set(session, opts), #destory(sid))<br>
<br>
maxAge: a number representing the milliseconds from Date.now() for expiry<br>
<br>
expires: a Date object indicating the cookie's expiration date (expires at the end of session by default).<br>
<br>
path: a string indicating the path of the cookie (/ by default).<br>
<br>
domain: a string indicating the domain of the cookie (no default).<br>
<br>
secure: a boolean indicating whether the cookie is only to be sent over HTTPS (false by default for HTTP, true by default for HTTPS).<br>
<br>
httpOnly: a boolean indicating whether the cookie is only to be sent over HTTP(S), and not made available to client JavaScript (true by default).<br>
<br>
signed: a boolean indicating whether the cookie is to be signed (false by default). If this is true, another cookie of the same name with the .sig suffix appended will also be sent, with a 27-byte url-safe base64 SHA1 value representing the hash of cookie-name=cookie-value against the first Keygrip key. This signature key is used to detect tampering the next time a cookie is received.<br>
<br>
overwrite: a boolean indicating whether to overwrite previously set cookies of the same name (false by default). If this is true, all cookies set during the same request with the same name (regardless of path or domain) are filtered out of the Set-Cookie header when setting this cookie.
License
MIT
KoaHub.js -- 基于 Koa.js 平台的 Node.js web 快速开发框架
官网:http://js.koahub.com

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

SublimeText3 Linux新版
SublimeText3 Linux最新版

记事本++7.3.1
好用且免费的代码编辑器

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中