Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yoho-activity-node
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
毕凯
9 years ago
Commit
f16403c60192fe28ea59391a2f2cba79b7746c08
1 parent
c535ed20
完善后端注释
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
11 additions
and
6 deletions
app.js
library/api.js
models/wxLottery/index.js
routes/wxLottery/index.js
util/error.js
views/error.hbs
app.js
View file @
f16403c
...
...
@@ -40,10 +40,11 @@ app.use('/', require('./router'));
// res.send(404, err);
// });
// 捕获全局错误,
非开发环境不
返回错误详情
// 捕获全局错误,
开发环境
返回错误详情
app
.
use
(
function
(
err
,
req
,
res
)
{
if
(
app
.
get
(
'env'
)
!
==
'development'
)
{
if
(
app
.
get
(
'env'
)
=
==
'development'
)
{
console
.
log
(
err
);
}
else
{
err
=
{};
}
res
.
status
(
err
.
status
||
500
);
...
...
library/api.js
View file @
f16403c
...
...
@@ -10,6 +10,7 @@ var errUtil = require('../util/error');
const
API_URL
=
'http://testapi.yoho.cn:28078'
;
// 最好有后端提供的各接口对应什么服务器说明,接口文档
// const DEV_API_URL = 'http://devapi.yoho.cn:58078';
// const SERVICE_URL = 'http://testservice.yoho.cn:28077';
// const YOHOBUY_URL = 'http://www.yohobuy.com';
...
...
@@ -21,6 +22,8 @@ class API {
'User-Agent'
:
'YOHO WEB NODE'
// TODO: 请求的服务端是否有要求格式,是否添加
};
this
.
timeout
=
5000
;
// TODO: 后端接口是否需求签名校验未知,如果需要需要添加
}
get
(
url
,
data
)
{
...
...
models/wxLottery/index.js
View file @
f16403c
...
...
@@ -12,6 +12,6 @@ module.exports = (data) => {
// 处理完成后,发给后端
data
=
Object
.
assign
({},
data
);
//
数据返回一个 Promise
//
所有数据返回一个 Promise,方便 Promise.all 调用
return
api
.
get
(
'/wx'
,
data
);
};
...
...
routes/wxLottery/index.js
View file @
f16403c
...
...
@@ -12,7 +12,7 @@ exports.index = (req, res) => {
// 传入参数给lotteryModel发送到后端,获取返回的数据
lotteryModel
({
test
:
1
}).
then
((
data
)
=>
{
// 接
受
接口返回到的数据,处理后,渲染页面或者返回 JSON
// 接
收
接口返回到的数据,处理后,渲染页面或者返回 JSON
res
.
send
(
data
);
// res.render('wxLottery/index', {
...
...
@@ -20,6 +20,6 @@ exports.index = (req, res) => {
// wxLottery: data
// });
}).
catch
((
err
)
=>
{
errUtil
.
webError
(
err
,
res
);
errUtil
.
webError
(
err
,
res
);
// 抓取 Promise 链的错误
});
};
...
...
util/error.js
View file @
f16403c
...
...
@@ -10,6 +10,7 @@ exports.apiError = (err) => {
exports
.
webError
=
(
err
,
res
)
=>
{
if
(
res
.
locals
.
isDevelop
)
{
console
.
log
(
err
);
}
else
{
err
=
{};
}
res
.
status
(
err
.
status
||
500
);
...
...
views/error.hbs
View file @
f16403c
#
默认错误页面
默认错误页面
...
...
Please
register
or
login
to post a comment