Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yohobuy-node
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
1
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
徐炜
8 years ago
Commit
458f2174c1be9b3b97008f81f7090da5e611e717
1 parent
7d26e058
客服开关
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
15 deletions
app.js
apps/common/controllers/cache.js → apps/common/controllers/secret-switch.js
apps/common/router.js
doraemon/middleware/secret-switch.js
app.js
View file @
458f217
...
...
@@ -82,11 +82,6 @@ app.use((req, res, next) => {
req
.
session
=
{};
}
// 获取客服开关,读cache
global
.
yoho
.
cache
.
get
(
'customerServiceSwitch'
).
then
(
resule
=>
{
res
.
locals
.
customerServiceSwitch
=
resule
||
false
;
}).
catch
(
next
);
next
();
});
...
...
@@ -104,6 +99,7 @@ try {
const
errorHanlder
=
require
(
'./doraemon/middleware/error-handler'
);
const
setPageInfo
=
require
(
'./doraemon/middleware/set-pageinfo'
);
const
pageCache
=
require
(
'./doraemon/middleware/page-cache'
);
const
secretSwitch
=
require
(
'./doraemon/middleware/secret-switch'
);
// YOHO 前置中间件
app
.
use
(
subDomain
());
...
...
@@ -114,7 +110,7 @@ try {
app
.
use
(
user
());
app
.
use
(
seo
());
app
.
use
(
setPageInfo
());
app
.
use
(
secretSwitch
());
app
.
use
(
pageCache
());
require
(
'./dispatch'
)(
app
);
...
...
apps/common/controllers/
cache
.js → apps/common/controllers/
secret-switch
.js
View file @
458f217
...
...
@@ -8,16 +8,13 @@
const
cache
=
global
.
yoho
.
cache
;
const
index
=
(
req
,
res
,
next
)
=>
{
let
customerServiceSwitch
=
req
.
query
.
customerServiceSwitch
;
const
param
=
req
.
query
[
'com.yohobuy.customerservice.enabled'
];
let
status
=
param
===
'true'
;
if
(
typeof
customerServiceSwitch
===
'undefined'
)
{
res
.
json
(
false
);
return
;
}
cache
.
set
(
'customerServiceSwitch'
,
customerServiceSwitch
?
true
:
false
,
-
1
).
then
(
result
=>
{
cache
.
set
(
'customerServiceSwitch'
,
status
,
0
).
then
(
result
=>
{
res
.
json
(
result
);
}).
catch
(
next
);
};
module
.
exports
=
{
...
...
apps/common/router.js
View file @
458f217
...
...
@@ -13,7 +13,7 @@ var multipart = require('connect-multiparty');
var
multipartMiddleware
=
multipart
();
const
rvCtrl
=
require
(
`
$
{
cRoot
}
/recent-view`
)
;
const
cache
=
require
(
`
$
{
cRoot
}
/
cache
`
)
;
const
cache
=
require
(
`
$
{
cRoot
}
/
secret-switch
`
)
;
const
uploadCtrl
=
require
(
`
$
{
cRoot
}
/upload`
)
;
const
erp2goods
=
require
(
`
$
{
cRoot
}
/erp2goods`
)
;
...
...
@@ -23,6 +23,6 @@ router.post('/upload/image', multipartMiddleware, uploadCtrl.uploadImg);
router
.
get
(
'/erp2goods'
,
erp2goods
.
find
);
router
.
get
(
'/
cache
'
,
cache
.
index
);
// 设置cache
router
.
get
(
'/
secret-switch
'
,
cache
.
index
);
// 设置cache
module
.
exports
=
router
;
...
...
doraemon/middleware/secret-switch.js
0 → 100644
View file @
458f217
const
logger
=
global
.
yoho
.
logger
;
const
secretSwitch
=
()
=>
{
return
(
req
,
res
,
next
)
=>
{
req
.
user
=
{};
// 全局的用户数据
req
.
yoho
=
{};
// req和res绑定yoho对象,用于传递全局数据, 如req.yoho.channel等
if
(
!
req
.
session
)
{
req
.
session
=
{};
}
// 获取客服开关,读cache
global
.
yoho
.
cache
.
get
(
'customerServiceSwitch'
).
then
(
result
=>
{
Object
.
assign
(
res
.
locals
,
{
customerServiceSwitch
:
result
||
false
});
next
();
}).
catch
((
err
)
=>
{
logger
.
error
(
err
);
next
();
});
};
};
module
.
exports
=
secretSwitch
;
...
...
Please
register
or
login
to post a comment