Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tke-eos
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QA
tke-eos
Commits
9fb4af14
Commit
9fb4af14
authored
Apr 22, 2019
by
xuezj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加校验
parent
8b6d391f
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
1 deletion
+67
-1
index.js
app/index.js
+2
-0
service.js
app/service.js
+5
-0
index.js
middleware/validate/index.js
+27
-0
package-lock.json
package-lock.json
+32
-1
package.json
package.json
+1
-0
No files found.
app/index.js
View file @
9fb4af14
...
...
@@ -6,6 +6,7 @@ const log4js = require('koa-log4')
const
logConf
=
require
(
'
../config/logger
'
)
const
error
=
require
(
'
../middleware/error
'
)
const
result
=
require
(
'
../middleware/result
'
)
const
validate
=
require
(
'
../middleware/validate
'
)
const
namespaceRoute
=
require
(
'
./namespace
'
)
const
serviceRoute
=
require
(
'
./service
'
)
...
...
@@ -28,6 +29,7 @@ function loadRoutes(router) {
router
.
use
(
error
())
.
use
(
result
())
.
use
(
validate
())
.
use
(
async
(
ctx
,
next
)
=>
{
// 腾讯云
ctx
.
container
=
container
...
...
app/service.js
View file @
9fb4af14
...
...
@@ -73,6 +73,11 @@ router.post('/create', async (ctx) => {
})
router
.
post
(
'
/details
'
,
async
(
ctx
)
=>
{
ctx
.
validate
(
ctx
.
Joi
.
object
().
keys
({
serviceName
:
ctx
.
Joi
.
string
().
required
(),
namespace
:
ctx
.
Joi
.
string
().
required
(),
}))
const
data
=
await
ctx
.
cluster
.
service_get
(
ctx
.
request
.
body
.
serviceName
,
ctx
.
request
.
body
.
namespace
)
ctx
.
body
=
ctx
.
ok
(
data
)
})
...
...
middleware/validate/index.js
View file @
9fb4af14
const
Joi
=
require
(
'
joi
'
)
function
ValidationError
(
message
)
{
this
.
name
=
'
ValidationError
'
this
.
message
=
message
||
''
}
ValidationError
.
prototype
=
Object
.
create
(
Error
.
prototype
);
ValidationError
.
prototype
.
constructor
=
ValidationError
;
module
.
exports
=
function
()
{
return
function
(
ctx
,
next
)
{
if
(
ctx
.
validate
)
{
return
next
()
}
ctx
.
Joi
=
Joi
ctx
.
validate
=
function
(
schema
)
{
const
target
=
ctx
.
method
===
'
GET
'
?
ctx
.
query
:
(
ctx
.
request
.
body
||
{})
const
result
=
ctx
.
Joi
.
validate
(
target
,
schema
)
if
(
result
.
error
)
{
throw
new
ValidationError
(
result
.
error
.
details
[
0
]
&&
result
.
error
.
details
[
0
].
message
)
}
}
return
next
()
}
}
package-lock.json
View file @
9fb4af14
...
...
@@ -2208,6 +2208,11 @@
}
}
},
"hoek"
:
{
"version"
:
"6.1.3"
,
"resolved"
:
"http://npmprivate.quantgroups.com/hoek/-/hoek-6.1.3.tgz"
,
"integrity"
:
"sha512-YXXAAhmF9zpQbC7LEcREFtXfGq5K1fmd+4PHkBq8NUqmzW3G+Dq10bI/i0KucLRwss3YYFQ0fSfoxBZYiGUqtQ=="
},
"hosted-git-info"
:
{
"version"
:
"2.7.1"
,
"resolved"
:
"http://npmprivate.quantgroups.com/hosted-git-info/-/hosted-git-info-2.7.1.tgz"
,
...
...
@@ -2631,6 +2636,14 @@
"resolved"
:
"http://registry.npm.taobao.org/isarray/download/isarray-0.0.1.tgz"
,
"integrity"
:
"sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
},
"isemail"
:
{
"version"
:
"3.2.0"
,
"resolved"
:
"http://npmprivate.quantgroups.com/isemail/-/isemail-3.2.0.tgz"
,
"integrity"
:
"sha512-zKqkK+O+dGqevc93KNsbZ/TqTUFd46MwWjYOoMrjIMZ51eU7DtQG3Wmd9SQQT7i7RVnuTPEiYEWHU3MSbxC1Tg=="
,
"requires"
:
{
"punycode"
:
"2.x.x"
}
},
"isexe"
:
{
"version"
:
"2.0.0"
,
"resolved"
:
"http://registry.npm.taobao.org/isexe/download/isexe-2.0.0.tgz"
,
...
...
@@ -2657,6 +2670,16 @@
"is-object"
:
"^1.0.1"
}
},
"joi"
:
{
"version"
:
"14.3.1"
,
"resolved"
:
"http://npmprivate.quantgroups.com/joi/-/joi-14.3.1.tgz"
,
"integrity"
:
"sha512-LQDdM+pkOrpAn4Lp+neNIFV3axv1Vna3j38bisbQhETPMANYRbFJFUyOZcOClYvM/hppMhGWuKSFEK9vjrB+bQ=="
,
"requires"
:
{
"hoek"
:
"6.x.x"
,
"isemail"
:
"3.x.x"
,
"topo"
:
"3.x.x"
}
},
"js-tokens"
:
{
"version"
:
"4.0.0"
,
"resolved"
:
"http://npmprivate.quantgroups.com/js-tokens/-/js-tokens-4.0.0.tgz"
,
...
...
@@ -3683,7 +3706,7 @@
},
"pseudomap"
:
{
"version"
:
"1.0.2"
,
"resolved"
:
"http://
npmprivate.quantgroups.com/pseudomap/-
/pseudomap-1.0.2.tgz"
,
"resolved"
:
"http://
registry.npm.taobao.org/pseudomap/download
/pseudomap-1.0.2.tgz"
,
"integrity"
:
"sha1-8FKijacOYYkX7wqKw0wa5aaChrM="
},
"psl"
:
{
...
...
@@ -4507,6 +4530,14 @@
"resolved"
:
"http://registry.npm.taobao.org/toidentifier/download/toidentifier-1.0.0.tgz"
,
"integrity"
:
"sha1-fhvjRw8ed5SLxD2Uo8j013UrpVM="
},
"topo"
:
{
"version"
:
"3.0.3"
,
"resolved"
:
"http://npmprivate.quantgroups.com/topo/-/topo-3.0.3.tgz"
,
"integrity"
:
"sha512-IgpPtvD4kjrJ7CRA3ov2FhWQADwv+Tdqbsf1ZnPUSAtCJ9e1Z44MmoSGDXGk4IppoZA7jd/QRkNddlLJWlUZsQ=="
,
"requires"
:
{
"hoek"
:
"6.x.x"
}
},
"touch"
:
{
"version"
:
"3.1.0"
,
"resolved"
:
"http://registry.npm.taobao.org/touch/download/touch-3.1.0.tgz"
,
...
...
package.json
View file @
9fb4af14
...
...
@@ -4,6 +4,7 @@
"description"
:
""
,
"main"
:
"bin/www.js"
,
"dependencies"
:
{
"
joi
"
:
"
^14.3.1
"
,
"
js-yaml
"
:
"
^3.12.1
"
,
"
koa
"
:
"
^2.6.2
"
,
"
koa-bodyparser
"
:
"
^4.2.1
"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment