Skip to content

Commit d312e0a

Browse files
committed
docs: change README & comment & UI to English
1 parent c76bc37 commit d312e0a

File tree

7 files changed

+32
-71
lines changed

7 files changed

+32
-71
lines changed

README.md

+7-46
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,13 @@
11
# Node.js Getting started
2-
在 LeanCloud 云引擎上使用 Express 的 Node.js 示例项目。
32

4-
若希望获取更多常见功能和代码片段,请访问 [leancloud/leanengine-nodejs-demos](https://github.com/leancloud/leanengine-nodejs-demos)
3+
A simple Node.js application based on [express] for LeanEngine Node.js runtime.
54

6-
## 本地运行
5+
[express]: https://expressjs.com/
76

8-
首先确认本机已经安装 [Node.js](http://nodejs.org/) 运行环境和 [LeanCloud 命令行工具](https://leancloud.cn/docs/leanengine_cli.html),然后执行下列指令:
7+
## Documentation
98

10-
```
11-
git clone https://github.com/leancloud/node-js-getting-started.git
12-
cd node-js-getting-started
13-
```
14-
15-
安装依赖:
16-
17-
```
18-
npm install
19-
```
20-
21-
登录并关联应用:
22-
23-
```
24-
lean login
25-
lean switch
26-
```
27-
28-
启动项目:
29-
30-
```
31-
lean up
32-
```
33-
34-
之后你就可以在 [localhost:3000](http://localhost:3000) 访问到你的应用了。
35-
36-
## 部署到 LeanEngine
37-
38-
部署到预备环境(若无预备环境则直接部署到生产环境):
39-
40-
```
41-
lean deploy
42-
```
43-
44-
## 相关文档
45-
46-
* [云函数开发指南](https://leancloud.cn/docs/leanengine_cloudfunction_guide-node.html)
47-
* [网站托管开发指南](https://leancloud.cn/docs/leanengine_webhosting_guide-node.html)
48-
* [JavaScript 开发指南](https://leancloud.cn/docs/leanstorage_guide-js.html)
9+
* [Node.js Web Hosting Guide](https://docs.leancloud.app/leanengine_webhosting_guide-node.html)
10+
* [Node.js Cloud Function Guide](https://docs.leancloud.app/leanengine_cloudfunction_guide-node.html)
11+
* [LeanStorage JavaScript Guide](https://docs.leancloud.app/leanstorage_guide-js.html)
4912
* [JavaScript SDK API](https://leancloud.github.io/javascript-sdk/docs/)
50-
* [Node.js SDK API](https://github.com/leancloud/leanengine-node-sdk/blob/master/API.md)
51-
* [命令行工具使用指南](https://leancloud.cn/docs/leanengine_cli.html)
52-
* [云引擎常见问题和解答](https://leancloud.cn/docs/leanengine_faq.html)
13+
* [lean-cli Guide](https://docs.leancloud.app/leanengine_cli.html)

app.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,24 @@ var cookieParser = require('cookie-parser');
77
var bodyParser = require('body-parser');
88
var AV = require('leanengine');
99

10-
// 加载云函数定义,你可以将云函数拆分到多个文件方便管理,但需要在主文件中加载它们
10+
// Loads cloud function defintions.
11+
// You can split it into multiple files but do not forget to load them in the main file.
1112
require('./cloud');
1213

1314
var app = express();
1415

15-
// 设置模板引擎
16+
// Configures template engine.
1617
app.set('views', path.join(__dirname, 'views'));
1718
app.set('view engine', 'ejs');
1819

19-
// 设置默认超时时间
20+
// Confirues default timeout.
2021
app.use(timeout('15s'));
2122

22-
// 加载云引擎中间件
23+
// Loads LeanEngine middleware.
2324
app.use(AV.express());
2425

2526
app.enable('trust proxy');
26-
// 需要重定向到 HTTPS 可去除下一行的注释。
27+
// Uncomment the following line to redirect all HTTP requests to HTTPS.
2728
// app.use(AV.Cloud.HttpsRedirect());
2829

2930
app.use(express.static('public'));
@@ -36,11 +37,11 @@ app.get('/', function(req, res) {
3637
res.render('index', { currentTime: new Date() });
3738
});
3839

39-
// 可以将一类的路由单独保存在一个文件中
40+
// You can store routings in multiple files according to their categories.
4041
app.use('/todos', require('./routes/todos'));
4142

4243
app.use(function(req, res, next) {
43-
// 如果任何一个路由都没有返回响应,则抛出一个 404 异常给后续的异常处理器
44+
// If there is no routing answering, throw a 404 exception to exception handlers.
4445
if (!res.headersSent) {
4546
var err = new Error('Not Found');
4647
err.status = 404;
@@ -51,7 +52,7 @@ app.use(function(req, res, next) {
5152
// error handlers
5253
app.use(function(err, req, res, next) {
5354
if (req.timedout && req.headers.upgrade === 'websocket') {
54-
// 忽略 websocket 的超时
55+
// Ignores websocket timeout.
5556
return;
5657
}
5758

@@ -60,13 +61,13 @@ app.use(function(err, req, res, next) {
6061
console.error(err.stack || err);
6162
}
6263
if (req.timedout) {
63-
console.error('请求超时: url=%s, timeout=%d, 请确认方法执行耗时很长,或没有正确的 response 回调。', req.originalUrl, err.timeout);
64+
console.error('Request timeout: url=%s, timeout=%d, please check whether its execute time is too long, or the response callback is not proper.', req.originalUrl, err.timeout);
6465
}
6566
res.status(statusCode);
66-
// 默认不输出异常详情
67+
// Do not output exception details by default.
6768
var error = {};
6869
if (app.get('env') === 'development') {
69-
// 如果是开发环境,则将异常堆栈输出到页面,方便开发调试
70+
// Displays exception stack on page if in the development enviroment.
7071
error = err;
7172
}
7273
res.render('error', {

cloud.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ const fs = require('fs')
33
const path = require('path')
44

55
/**
6-
* 加载 functions 目录下所有的云函数
6+
* Loads all cloud functions under the `functions` directory.
77
*/
88
fs.readdirSync(path.join(__dirname, 'functions')).forEach( file => {
99
require(path.join(__dirname, 'functions', file))
1010
})
1111

1212
/**
13-
* 一个简单的云代码方法
13+
* A simple cloud function.
1414
*/
1515
AV.Cloud.define('hello', function(request) {
1616
return 'Hello world!'

routes/todos.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var AV = require('leanengine');
44

55
var Todo = AV.Object.extend('Todo');
66

7-
// 查询 Todo 列表
7+
// Todo list
88
router.get('/', function(req, res, next) {
99
var query = new AV.Query(Todo);
1010
query.descending('createdAt');
@@ -15,8 +15,7 @@ router.get('/', function(req, res, next) {
1515
});
1616
}, function(err) {
1717
if (err.code === 101) {
18-
// 该错误的信息为:{ code: 101, message: 'Class or object doesn\'t exists.' },说明 Todo 数据表还未创建,所以返回空的 Todo 列表。
19-
// 具体的错误代码详见:https://leancloud.cn/docs/error_code.html
18+
// Todo class does not exist in the cloud yet.
2019
res.render('todos', {
2120
title: 'TODO 列表',
2221
todos: []
@@ -27,7 +26,7 @@ router.get('/', function(req, res, next) {
2726
}).catch(next);
2827
});
2928

30-
// 新增 Todo 项目
29+
// Creates a new todo item.
3130
router.post('/', function(req, res, next) {
3231
var content = req.body.content;
3332
var todo = new Todo();

server.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ AV.init({
88
masterKey: process.env.LEANCLOUD_APP_MASTER_KEY
99
});
1010

11-
// 如果不希望使用 masterKey 权限,可以将下面一行删除
11+
// Comment the following line if you do not want to use masterKey.
1212
AV.Cloud.useMasterKey();
1313

1414
var app = require('./app');
1515

16-
// 端口一定要从环境变量 `LEANCLOUD_APP_PORT` 中获取。
17-
// LeanEngine 运行时会分配端口并赋值到该变量。
16+
// Retrieves the port number from environment variable `LEANCLOUD_APP_PORT`.
17+
// LeanEngine runtime will assign a port and set the environment variable automatically.
1818
var PORT = parseInt(process.env.LEANCLOUD_APP_PORT || process.env.PORT || 3000);
1919

2020
app.listen(PORT, function (err) {
2121
console.log('Node app is running on port:', PORT);
2222

23-
// 注册全局未捕获异常处理器
23+
// Registers a global exception handler for uncaught exceptions.
2424
process.on('uncaughtException', function(err) {
2525
console.error('Caught exception:', err.stack);
2626
});

views/index.ejs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
</head>
77
<body>
88
<h1>LeanEngine</h1>
9-
<p>这是 LeanEngine 的示例应用</p>
10-
<p>当前时间:<%= currentTime %></p>
11-
<p><a href="/todos">一个简单的「TODO 列表」示例</a></p>
9+
<p>This is a LeanEngine demo application.</p>
10+
<p>Current date: <%= currentTime %></p>
11+
<p><a href="/todos">A simple todo demo</a></p>
1212
</body>
1313
</html>

views/todos.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<h1><%= title %></h1>
99
<form action="/todos" method="POST">
1010
<input type="text" name="content" />
11-
<input type="submit" value="新增" />
11+
<input type="submit" value="new todo" />
1212
</form>
1313
<ul>
1414
<% for(var i=0; i<todos.length; i++) {%>

0 commit comments

Comments
 (0)