Skip to content

Commit 8efa257

Browse files
object-kazmaslow
andauthored
fix: error of process is not defined (#146)
* docs: update docs; * fix: error on opening app-console Co-authored-by: maslow <[email protected]>
1 parent 6d111b2 commit 8efa257

File tree

16 files changed

+215
-126
lines changed

16 files changed

+215
-126
lines changed

docs/.vitepress/.temp/CNAME

-1
This file was deleted.

docs/.vitepress/.temp/logo.png

-4.21 KB
Binary file not shown.

docs/.vitepress/.temp/zhuo.png

-85.5 KB
Binary file not shown.

docs/.vitepress/config.js

+7-11
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@ const NavConfig = [
99
{ text: '开发指南', link: '/guide/', activeMatch: '^/guide/' },
1010
{ text: '预览图', link: '/screenshots', },
1111
{ text: '在线 Demo', link: '/todo-list', },
12-
{ text: 'lafyun.com', link: 'https://www.lafyun.com/' },
1312
{
14-
text: '更新记录',
15-
link: 'https://github.com/labring/laf/blob/main/CHANGELOG.md'
16-
},
17-
{
18-
text: 'GitHub',
19-
link: 'https://github.com/labring/laf'
13+
text: '控制台',
14+
// target: "_self",
15+
link: 'https://console.lafyun.com/'
2016
}
2117
]
2218

@@ -168,15 +164,15 @@ const GuideSiderbarConfig = [
168164

169165
export default defineConfig({
170166
lang: 'zh-CN',
171-
title: 'laf 云开发文档',
172-
description: 'laf 云开发开发者使用文档',
167+
title: 'laf 云开发',
168+
description: 'laf 云开发,像写博客一样写函数,随手上线',
173169

174170
themeConfig: {
175171
logo: '/logo.png',
176-
// repo: 'labring/laf',
172+
repo: 'labring/laf',
177173
// docsRepo: 'labring/laf-docs',
178174
docsBranch: 'main',
179-
docsDir: '',
175+
docsDir: 'docs',
180176
editLinks: true,
181177
editLinkText: '在 GitHub 上编辑此页',
182178
lastUpdated: '更新于',

docs/guide/quick-start/index.md

+62-66
Original file line numberDiff line numberDiff line change
@@ -9,60 +9,59 @@ title: 快速开始
99
:::
1010

1111
### 准备工作
12-
13-
1. 你需要在 [lafyun.com](https://www.lafyun.com) 上注册一个账户
14-
2. 登录到 [lafyun.com](https://www.lafyun.com) 控制台 ,点击左上角的 `新建` 按钮,创建一个空应用
15-
3. 待应用成功启动后,点击右侧 「开发」 按钮,进入应用的「开发控制台」,接下来,我们将在「开发控制台」 进行第一个 `laf` 应用的功能开发
12+
13+
1. 你需要在 [lafyun.com](https://console.lafyun.com) 上注册一个账户
14+
2. 登录到 [lafyun.com 控制台](https://console.lafyun.com),点击左上角的 `新建` 按钮,创建一个空应用
15+
3. 待应用成功启动后,点击右侧 「开发」 按钮,进入应用的「开发控制台」,接下来,我们将在「开发控制台」 进行第一个 `laf` 应用的功能开发
1616

1717
### 编写云函数
1818

19-
本教程会编写两个云函数:
19+
本教程会编写两个云函数:
20+
2021
- `register` 处理注册请求
2122
- `login` 处理登录请求.
2223

23-
24-
25-
2624
#### 用户注册云函数
27-
25+
2826
::: info
2927
在「云函数」管理页面,点击 「新建函数」,创建注册云函数 `register`
3028

3129
点击 `register` 函数右侧的 「开发」按钮,进入 WebIDE,编写以下代码:
3230
:::
3331

3432
```ts
35-
import cloud from '@/cloud-sdk'
36-
import { createHash } from 'crypto'
33+
import cloud from "@/cloud-sdk";
34+
import { createHash } from "crypto";
3735

3836
exports.main = async function (ctx: FunctionContext) {
39-
const username = ctx.body?.username || ''
40-
const password = ctx.body?.password || ''
37+
const username = ctx.body?.username || "";
38+
const password = ctx.body?.password || "";
4139

4240
// check param
43-
if (!/[a-zA-Z0-9]{3,16}/.test(username)) return { error: 'invalid username' }
44-
if (!/[a-zA-Z0-9]{3,16}/.test(password)) return { error: 'invalid password' }
41+
if (!/[a-zA-Z0-9]{3,16}/.test(username)) return { error: "invalid username" };
42+
if (!/[a-zA-Z0-9]{3,16}/.test(password)) return { error: "invalid password" };
4543

4644
// check username existed
47-
const db = cloud.database()
48-
const exists = await db.collection('users')
45+
const db = cloud.database();
46+
const exists = await db
47+
.collection("users")
4948
.where({ username: username })
50-
.count()
49+
.count();
5150

52-
if(exists.total > 0) return { error: 'username already existed'}
51+
if (exists.total > 0) return { error: "username already existed" };
5352

5453
// add user
55-
const { id } = await db.collection('users')
56-
.add({
57-
username: username,
58-
password: createHash('sha256').update(password).digest('hex'),
59-
created_at: new Date()
60-
})
54+
const { id } = await db.collection("users").add({
55+
username: username,
56+
password: createHash("sha256").update(password).digest("hex"),
57+
created_at: new Date(),
58+
});
6159

62-
console.log('user registered: ', id)
63-
return { data: id }
64-
}
60+
console.log("user registered: ", id);
61+
return { data: id };
62+
};
6563
```
64+
6665
::: info
6766
点击右上角的 「显示调试面板」(Ctrl/Cmd + B) 即可调试运行,点击 「保存」 & 「发布」 函数即发布上线!
6867
:::
@@ -72,49 +71,48 @@ exports.main = async function (ctx: FunctionContext) {
7271
> 同上,创建 `login` 云函数,编写以下代码:
7372
7473
```ts
75-
import cloud from '@/cloud-sdk'
76-
import { createHash } from 'crypto'
74+
import cloud from "@/cloud-sdk";
75+
import { createHash } from "crypto";
7776

7877
exports.main = async function (ctx: FunctionContext) {
79-
const username = ctx.body?.username || ''
80-
const password = ctx.body?.password || ''
78+
const username = ctx.body?.username || "";
79+
const password = ctx.body?.password || "";
8180

8281
// check user login
83-
const db = cloud.database()
84-
const res = await db.collection('users')
82+
const db = cloud.database();
83+
const res = await db
84+
.collection("users")
8585
.where({
8686
username: username,
87-
password: createHash('sha256').update(password).digest('hex')
87+
password: createHash("sha256").update(password).digest("hex"),
8888
})
89-
.getOne()
89+
.getOne();
90+
91+
if (!res.data) return { error: "invalid username or password" };
9092

91-
if (!res.data)
92-
return { error: 'invalid username or password' }
93-
9493
// generate jwt token
95-
const user_id = res.data._id
94+
const user_id = res.data._id;
9695
const payload = {
9796
uid: user_id,
98-
exp: Math.floor(Date.now() / 1000) + 60 * 60 * 24 * 7
99-
}
97+
exp: Math.floor(Date.now() / 1000) + 60 * 60 * 24 * 7,
98+
};
10099

101-
const access_token = cloud.getToken(payload)
100+
const access_token = cloud.getToken(payload);
102101

103102
return {
104103
uid: res.data._id,
105-
access_token: access_token
106-
}
107-
}
104+
access_token: access_token,
105+
};
106+
};
108107
```
109108

110109
> 点击右上角的 「显示调试面板」(Ctrl/Cmd + B) 即可调试运行,点击 「保存」 & 「发布」 函数即发布上线!
111110
112-
113-
114111
### 使用 curl 调用云函数
115112

116113
你可以通过云函数列表页面,查看 & 复制云函数的调用地址,
117114
或将以下 curl 命令中的 `APPID` 替换成你的 APPID 后执行:
115+
118116
```bash
119117
# 注册用户
120118
curl -X POST -H "Content-Type: application/json" -d '{"username": "admin", "password": "admin"}' https://APPID.lafyun.com/register
@@ -133,47 +131,45 @@ curl -X POST -H "Content-Type: application/json" -d '{"username": "admin", "pass
133131
npm install laf-client-sdk
134132
```
135133

136-
137134
```ts
138135
// user.ts
139136

140-
import { Cloud } from 'laf-client-sdk'
137+
import { Cloud } from "laf-client-sdk";
141138

142-
const cloud = new Cloud({
139+
const cloud = new Cloud({
143140
baseUrl: "https://APPID.lafyun.com",
144-
getAccessToken: () => localStorage.getItem('access_token')
145-
})
141+
getAccessToken: () => localStorage.getItem("access_token"),
142+
});
146143

147144
// regiser function
148145
export async function register(username: string, password: string) {
149-
const res = await cloud.invoke('register', {
146+
const res = await cloud.invoke("register", {
150147
username: username,
151-
password: password
152-
})
148+
password: password,
149+
});
153150

154-
return res
151+
return res;
155152
}
156153

157154
// login function
158155
export async function login(username: string, password: string) {
159-
const res = await cloud.invoke('login', {
156+
const res = await cloud.invoke("login", {
160157
username: username,
161-
password: password
162-
})
158+
password: password,
159+
});
163160

164-
if(res.access_token) {
161+
if (res.access_token) {
165162
// save token
166-
localStorage.setItem('access_token', res.access_token)
163+
localStorage.setItem("access_token", res.access_token);
167164
}
168165

169-
return res
166+
return res;
170167
}
171168
```
172169

173170
> 最后,可以在你的 Vue/React/Angular/小程序 页面中调用这两个云函数完成具体的登录注册功能!
174171
175-
176172
### 其他
177173

178-
- 我们可以在开发控制台,查看云函数的调用日志,在线调试等
179-
- 如果调用返回 404,请检查函数名是否拼写错误,或者云函数是否已经发布
174+
- 我们可以在开发控制台,查看云函数的调用日志,在线调试等
175+
- 如果调用返回 404,请检查函数名是否拼写错误,或者云函数是否已经发布

docs/index.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ features:
2424
footer: Apache License V2.0 | Copyright © 2021-present labring/laf
2525
---
2626

27-
2827
## 🖥 在线体验
2928

29+
::: info
3030
🎉 [lafyun.com](http://www.lafyun.com)`laf` 的一个在线版,可在免费线体验 `laf` 云开发应用服务!
3131

32-
开发者可免费在 [lafyun.com](http://www.lafyun.com) 上快速创建自己的应用,免除服务器部署和运维工作,立即拥有应用独立域名及 HTTPS 证书,快速上线应用!
32+
开发者可免费在 [lafyun.com 控制台](http://console.lafyun.com) 上快速创建自己的应用,免除服务器部署和运维工作,立即拥有应用独立域名及 HTTPS 证书,快速上线应用!
33+
:::

docs/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.8.2",
2+
"version": "0.8.3",
33
"name": "laf-docs",
44
"private": true,
55
"scripts": {
@@ -13,4 +13,4 @@
1313
"dependencies": {
1414
"vitepress": "^0.22.4"
1515
}
16-
}
16+
}

packages/web/.env.development

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# just a flag
22
ENV = 'development'
33

4-
VUE_APP_APP_CONSOLE_URI = 'http://localhost:9528/app-console'
4+
VITE_APP_CONSOLE_URI = 'http://localhost:9528/app-console'

packages/web/.env.production

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# just a flag
22
ENV = 'production'
33

4-
VUE_APP_APP_CONSOLE_URI = '/app-console'
4+
VITE_APP_CONSOLE_URI = '/app-console'

packages/web/.vscode/extensions.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
"vue.volar",
99
"dbaeumer.vscode-eslint"
1010
]
11-
}
11+
}

packages/web/.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
"i18n.global.t('${key}')"
2525
]
2626
}]
27-
}
27+
}

packages/web/env.d.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference types="vite/client" />
2+
3+
interface ImportMetaEnv {
4+
readonly VITE_APP_CONSOLE_URI: string
5+
// 更多环境变量...
6+
}
7+
8+
interface ImportMeta {
9+
readonly env: ImportMetaEnv
10+
}

packages/web/src/api/application.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export async function initApplicationWithTemplate(appid, template_id) {
176176
*/
177177
export async function openAppConsole(app) {
178178
const base_url = getCurrentBaseURL()
179-
const console_uri = process.env.VUE_APP_APP_CONSOLE_URI
179+
const console_uri = import.meta.env.VITE_APP_CONSOLE_URI
180180
const back_url = encodeURIComponent(window.location.href)
181181

182182
let app_console_url = `${console_uri}/#/app/${app.appid}/dashboard/index?$back_url=${back_url}`

packages/web/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
}
2525
},
2626
"exclude": ["dist", "node_modules"]
27-
}
27+
}

0 commit comments

Comments
 (0)