Browse
---
Chat
---
Wekan
Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
os
npm-util
Commits
61f6d685
Commit
61f6d685
authored
7 years ago
by
kc
Browse files
Options
Download
Email Patches
Plain Diff
Check responses before parsing. Use dev image tag in dev inv
parent
d985d8a0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
api/index.js
+6
-0
api/index.js
auth/index.js
+19
-7
auth/index.js
package.json
+1
-1
package.json
service/index.js
+1
-1
service/index.js
with
27 additions
and
9 deletions
+27
-9
api/index.js
+
6
-
0
View file @
61f6d685
...
...
@@ -15,6 +15,12 @@ function defaultMessage(type, err) {
window
.
HOST
=
location
.
protocol
+
"
//
"
+
location
.
host
;
// TODO: Check the return status of our call. If we get a 404 try again X times
// until we either get a response or hit the retry limit.
// On a reverse proxy server we should actually try capturing any 404's (if they make it there)
// and retrying on another docker task (if it works that way)
const
api
=
{
get
:
function
(
type
,
opts
,
callback
)
{
...
...
This diff is collapsed.
Click to expand it.
auth/index.js
+
19
-
7
View file @
61f6d685
...
...
@@ -47,6 +47,17 @@ module.exports = {
if
(
this
.
AUTH_URL
)
{
return
this
.
AUTH_URL
}
},
checkResponse
(
raw
,
requestFrom
)
{
let
res
=
""
try
{
res
=
raw
?
JSON
.
parse
(
raw
)
:
""
}
catch
(
e
)
{
console
.
log
(
`ERR -
${
requestFrom
}
Invalid request/url`
);
console
.
log
(
`ERR -
${
requestFrom
}
:`
,
e
);
return
false
}
return
true
},
checkAccess
({
headers
=
{},
app
,
accessReq
})
{
let
customHeaders
=
{
...
...
@@ -67,12 +78,9 @@ module.exports = {
res
.
on
(
"
data
"
,
(
data
)
=>
raw
+=
data
.
toString
())
res
.
on
(
"
err
"
,
(
err
)
=>
{
reject
(
err
)
})
res
.
on
(
"
end
"
,
()
=>
{
let
res
=
""
try
{
res
=
raw
?
JSON
.
parse
(
raw
)
:
""
}
catch
(
e
)
{
console
.
log
(
"
Invalid request/url - options:
"
,
options
);
console
.
log
(
"
e:
"
,
e
);
}
let
responseIsOk
=
this
.
checkResponse
(
raw
,
"
NPMAUTH.CHECKACCESS
"
)
if
(
!
responseIsOk
)
{
return
respond
({
status
:
false
})
}
let
res
=
JSON
.
parse
(
raw
)
let
status
=
res
.
status
?
res
.
status
:
false
let
hasPermissions
=
status
&&
res
.
access
[
app
]
>=
res
.
access
[
"
levels
"
][
accessReq
]
resolve
({
status
:
status
,
hasPermissions
})
...
...
@@ -107,7 +115,9 @@ module.exports = {
respond
({
status
:
false
,
data
:
"
Server error
"
})
})
res
.
on
(
"
end
"
,
()
=>
{
let
res
=
raw
?
JSON
.
parse
(
raw
)
:
""
let
responseIsOk
=
this
.
checkResponse
(
raw
,
"
NPMAUTH.GETMENU
"
)
if
(
!
responseIsOk
)
{
return
respond
({
status
:
false
})
}
let
res
=
JSON
.
parse
(
raw
)
if
(
!
res
.
status
)
{
if
(
res
.
data
)
{
console
.
log
(
res
.
data
);
...
...
@@ -148,6 +158,8 @@ module.exports = {
res
.
on
(
"
data
"
,
(
data
)
=>
raw
+=
data
.
toString
())
res
.
on
(
"
err
"
,
(
err
)
=>
{
reject
(
err
)
})
res
.
on
(
"
end
"
,
()
=>
{
let
responseIsOk
=
this
.
checkResponse
(
raw
,
"
NPMAUTH.LOGOUT
"
)
if
(
!
responseIsOk
)
{
return
respond
({
status
:
false
})
}
let
res
=
JSON
.
parse
(
raw
)
resolve
({
status
:
res
.
status
})
})
...
...
This diff is collapsed.
Click to expand it.
package.json
+
1
-
1
View file @
61f6d685
{
"name"
:
"os-npm-util"
,
"version"
:
"0.4.
0
"
,
"version"
:
"0.4.
1
"
,
"description"
:
"NPM Modules"
,
"main"
:
"index.js"
,
"dependencies"
:
{
...
...
This diff is collapsed.
Click to expand it.
service/index.js
+
1
-
1
View file @
61f6d685
...
...
@@ -9,7 +9,7 @@ const yaml = require("js-yaml");
const
yamlFile
=
fs
.
readFileSync
(
"
/home/app/docker-compose.yml
"
)
const
yamlObj
=
yaml
.
safeLoad
(
yamlFile
)
const
MAIN_SERVICE
=
yamlObj
.
services
.
main
const
MAIN_SERVICE
=
process
.
env
.
DEV_ENV
?
yamlObj
.
services
.
dev
:
yamlObj
.
services
.
main
const
DOCKER_IMAGE
=
MAIN_SERVICE
.
image
const
IMAGE_VER
=
DOCKER_IMAGE
.
match
(
/:
(
.+
)
/
)[
1
]
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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
Menu
Explore
Projects
Groups
Snippets