Skip to content

Commit

Permalink
docs: update serverless session
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 committed Feb 4, 2024
1 parent 17b8b23 commit ce69700
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 4 deletions.
39 changes: 37 additions & 2 deletions site/docs/cookie_session.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Cookie 在 Web 应用中经常承担标识请求方身份的功能,所以 Web

## 适用范围

* @midwayjs/web 下(即 egg)内置的是 egg 自带的 Cookie,未提供替换能力,不适用本文档
* @midwayjs/express 下(即 express)内置的是 express 自带的 Cookie 库,未提供替换能力,不适用本文档
* `@midwayjs/web` 下(即 egg)内置的是 egg 自带的 Cookie,未提供替换能力,不适用本文档
* `@midwayjs/express` 下(即 express)内置的是 express 自带的 Cookie 库,未提供替换能力,不适用本文档



Expand Down Expand Up @@ -230,6 +230,41 @@ export default {



## 函数下的 Session

在函数弹性容器的场景下,默认未内置 Session 模块,如果需要可以手动添加。

```json
{
"dependencies": {
"@midwayjs/session": "^3.0.0",
// ...
},
}
```

在 configuration 中引入组件。

```typescript
// src/configuration.ts
import { Configuration } from '@midwayjs/core';
import * as faas from '@midwayjs/faas';
import * as session from '@midwayjs/session';

@Configuration({
imports: [
faas,
session,
// ...
]
})
export class MainConfiguration {
// ...
}
```



## Session 示例

### 修改用户 Session 失效时间
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Cookie often assume the function of identifying the requestor's identity in Web

## Scope of application

* The built-in cookie under @midwayjs/web (i.e. egg) is the cookie that comes with egg. It does not provide replacement capabilities and is not applicable to this document.
* The built-in cookie library under @midwayjs/express (i.e. express) is the cookie library that comes with express. It does not provide replacement capabilities and is not applicable to this document.
* The built-in cookie under `@midwayjs/web` (i.e. egg) is the cookie that comes with egg. It does not provide replacement capabilities and is not applicable to this document.
* The built-in cookie library under `@midwayjs/express` (i.e. express) is the cookie library that comes with express. It does not provide replacement capabilities and is not applicable to this document.



Expand Down Expand Up @@ -230,6 +230,41 @@ It can be seen that these parameters are cookie parameters except `key`. `key` r



## Session in Serverless

In the scenario of a function elastic container, the Session module is not built-in by default. You can add it manually if necessary.

```json
{
"dependencies": {
"@midwayjs/session": "^3.0.0",
// ...
},
}
```

Introduce components in configuration.

```typescript
// src/configuration.ts
import { Configuration } from '@midwayjs/core';
import * as faas from '@midwayjs/faas';
import * as session from '@midwayjs/session';

@Configuration({
imports: [
faas,
session,
// ...
]
})
export class MainConfiguration {
// ...
}
```



## Session example

### Modify user Session expiration time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,35 @@ If you encounter something more complex, you can use the [raw query method](http



### 4. TS2612 error

If your model reports a TS2612 error, such as:

```
src/entity/AesTenantConfigInfo.ts:29:6 - error TS2612: Property 'id' will overwrite the base property in 'Model<AesTenantConfigInfoAttributes, AesTenantConfigInfoAttributes>'. If this is intentional, add an initializer. Otherwise, add a 'declare' modifier or remove the redundant declaration.
29 id?: number;
~~
```

It can be assigned a null value.

```typescript
import { Table, Column } from 'sequelize-typescript';

@Table
export class User extends Model {
@Column({
primaryKey: true,
autoIncrement: true,
type: DataType.BIGINT,
})
id?: number = undefined;
}
```



## Other

- The above document is translated from sequelize-typescript. For more API, please refer to the [English document](<(https://github.com/sequelize/sequelize-typescrip)>).
Expand Down

0 comments on commit ce69700

Please sign in to comment.