Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
node-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
project-templates
web
node-api
Commits
5717ff16
Commit
5717ff16
authored
Apr 17, 2019
by
Vadym Gidulian
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev'
parents
abf68b72
e57445b0
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
61 additions
and
46 deletions
+61
-46
package.json
package.json
+3
-3
api.js
src/utils/api.js
+11
-4
db.js
src/utils/db.js
+6
-10
grace.js
src/utils/grace.js
+1
-1
util.js
src/utils/util.js
+12
-0
yarn.lock
yarn.lock
+28
-28
No files found.
package.json
View file @
5717ff16
...
...
@@ -5,11 +5,11 @@
"dependencies"
:
{
"
axios
"
:
"
^0.18.0
"
,
"
express
"
:
"
^4.16.4
"
,
"
mongodb
"
:
"
^3.
1.1
3
"
,
"
mongodb
"
:
"
^3.
2.
3
"
,
"
response-time
"
:
"
^2.3.2
"
,
"
@gviagroup/seqid-gen-api
"
:
"
^1.0.0
"
},
"devDependencies"
:
{
"
nodemon
"
:
"
^1.18.
9
"
"
nodemon
"
:
"
^1.18.
11
"
}
}
src/utils/api.js
View file @
5717ff16
...
...
@@ -20,7 +20,9 @@ module.exports = {
await
requestValidator
(
req
,
res
,
_next
);
if
(
nextWatcher
.
wasCalled
)
return
nextWatcher
.
doNext
();
}
catch
(
e
)
{
// Probably bad request
return
res
.
status
(
400
).
send
(
e
.
message
);
return
res
.
status
(
400
)
.
set
(
'Content-Type'
,
'text/plain'
)
.
send
(
e
.
message
);
}
}
...
...
@@ -30,7 +32,9 @@ module.exports = {
if
(
nextWatcher
.
wasCalled
)
return
nextWatcher
.
doNext
();
}
catch
(
e
)
{
// Operation error
const
code
=
e
.
code
||
(
e
.
response
&&
e
.
response
.
code
);
if
(
/^4
\d\d
/
.
test
(
code
))
return
res
.
status
(
code
).
send
(
e
.
message
);
if
(
/^4
\d\d
/
.
test
(
code
))
return
res
.
status
(
code
)
.
set
(
'Content-Type'
,
'text/plain'
)
.
send
(
e
.
message
);
return
next
(
e
);
}
...
...
@@ -45,9 +49,12 @@ module.exports = {
}
}
if
(
!
response
&&
!
res
[
IS_EMPTY
])
return
res
.
status
(
404
).
send
(
response
);
if
(
!
response
&&
!
res
[
IS_EMPTY
])
return
res
.
status
(
404
).
send
();
res
.
status
(
res
.
statusCode
||
200
).
send
(
response
);
if
(
res
[
IS_EMPTY
]
||
[
204
,
304
].
includes
(
res
.
statusCode
))
response
=
null
;
res
.
status
(
res
.
statusCode
||
200
)
.
send
((
typeof
response
===
'number'
)
?
String
(
response
)
:
response
);
}
},
...
...
src/utils/db.js
View file @
5717ff16
'use strict'
;
const
grace
=
require
(
'./grace'
);
const
{
createError
,
logError
,
logInfo
,
logWarn
}
=
require
(
'./log'
);
const
{
checkEnvironmentVariables
}
=
require
(
'./util'
);
[
'MONGODB_URI'
,
'SEQID_GEN_API'
].
forEach
(
varname
=>
{
if
(
!
process
.
env
[
varname
])
{
logError
(
`Environment variable
${
varname
}
is not defined!`
);
grace
.
shutdown
(
1
);
}
});
checkEnvironmentVariables
(
'MONGODB_URI'
,
'SEQID_GEN_API'
);
const
{
MongoClient
}
=
require
(
'mongodb'
);
const
SeqidGenApi
=
require
(
'@gviagroup/seqid-gen-api'
);
const
grace
=
require
(
'./grace'
);
const
{
createError
,
logError
,
logInfo
,
logWarn
}
=
require
(
'./log'
);
let
mongoClient
=
null
;
const
seqidGen
=
new
SeqidGenApi
(
process
.
env
.
SEQID_GEN_API
);
...
...
src/utils/grace.js
View file @
5717ff16
...
...
@@ -42,7 +42,7 @@ module.exports = {
async
shutdown
(
code
)
{
logInfo
(
'Server is shutting down gracefully...'
);
await
thi
s
.
handleShutdown
();
await
module
.
export
s
.
handleShutdown
();
process
.
exit
(
code
||
0
);
}
...
...
src/utils/util.js
View file @
5717ff16
'use strict'
;
const
{
shutdown
}
=
require
(
'./grace'
);
const
{
logError
}
=
require
(
'./log'
);
module
.
exports
=
{
checkEnvironmentVariables
(...
varNames
)
{
for
(
const
varName
of
varNames
)
{
if
(
!
process
.
env
[
varName
])
{
logError
(
`Environment variable
${
varName
}
is not set!`
);
shutdown
(
1
);
}
}
}
};
yarn.lock
View file @
5717ff16
...
...
@@ -191,10 +191,10 @@ braces@^2.3.1, braces@^2.3.2:
split-string "^3.0.2"
to-regex "^3.0.1"
bson@^1.1.
0
:
version "1.1.
0
"
resolved "https://npm.gvia.group/bson/-/bson-1.1.
0.tgz#bee57d1fb6a87713471af4e32bcae36de814b5b0
"
integrity sha512-
9Aeai9TacfNtWXOYarkFJRW2CWo+dRon+fuLZYJmvLV3+MiUp0bEI6IAZfXEIg7/Pl/7IWlLaDnhzTsD81etQA
==
bson@^1.1.
1
:
version "1.1.
1
"
resolved "https://npm.gvia.group/bson/-/bson-1.1.
1.tgz#4330f5e99104c4e751e7351859e2d408279f2f13
"
integrity sha512-
jCGVYLoYMHDkOsbwJZBCqwMHyH4c+wzgI9hG7Z6SZJRXWr+x58pdIbm2i9a/jFGCkRJqRUr8eoI7lDWa0hTkxg
==
bytes@3.0.0:
version "3.0.0"
...
...
@@ -235,10 +235,10 @@ chalk@^2.0.1:
escape-string-regexp "^1.0.5"
supports-color "^5.3.0"
chokidar@^2.
0.4
:
version "2.1.
0
"
resolved "https://npm.gvia.group/chokidar/-/chokidar-2.1.
0.tgz#5fcb70d0b28ebe0867eb0f09d5f6a08f29a1efa0
"
integrity sha512-
5t6G2SH8eO6lCvYOoUpaRnF5Qfd//gd7qJAkwRUw9qlGVkiQ13uwQngqbWWaurOsaAm9+kUGbITADxt6H0XFNQ
==
chokidar@^2.
1.5
:
version "2.1.
5
"
resolved "https://npm.gvia.group/chokidar/-/chokidar-2.1.
5.tgz#0ae8434d962281a5f56c72869e79cb6d9d86ad4d
"
integrity sha512-
i0TprVWp+Kj4WRPtInjexJ8Q+BqTE909VpH8xVhXrJkoc5QC8VO9TryGOqTr+2hljzc1sC62t22h5tZePodM/A
==
dependencies:
anymatch "^2.0.0"
async-each "^1.0.1"
...
...
@@ -250,7 +250,7 @@ chokidar@^2.0.4:
normalize-path "^3.0.0"
path-is-absolute "^1.0.0"
readdirp "^2.2.1"
upath "^1.1.
0
"
upath "^1.1.
1
"
optionalDependencies:
fsevents "^1.2.7"
...
...
@@ -1193,23 +1193,23 @@ mkdirp@^0.5.0, mkdirp@^0.5.1:
dependencies:
minimist "0.0.8"
mongodb-core@
3.1.11
:
version "3.
1.11
"
resolved "https://npm.gvia.group/mongodb-core/-/mongodb-core-3.
1.11.tgz#b253038dbb4d7329f3d1c2ee5400bb0c9221fde5
"
integrity sha512-
rD2US2s5qk/ckbiiGFHeu+yKYDXdJ1G87F6CG3YdaZpzdOm5zpoAZd/EKbPmFO6cQZ+XVXBXBJ660sSI0gc6qg
==
mongodb-core@
^3.2.3
:
version "3.
2.3
"
resolved "https://npm.gvia.group/mongodb-core/-/mongodb-core-3.
2.3.tgz#eb9bcb876f169f5843fd135f7f7686dbac0e9e34
"
integrity sha512-
UyI0rmvPPkjOJV8XGWa9VCTq7R4hBVipimhnAXeSXnuAPjuTqbyfA5Ec9RcYJ1Hhu+ISnc8bJ1KfGZd4ZkYARQ
==
dependencies:
bson "^1.1.
0
"
bson "^1.1.
1
"
require_optional "^1.0.1"
safe-buffer "^5.1.2"
optionalDependencies:
saslprep "^1.0.0"
mongodb@^3.
1.1
3:
version "3.
1.1
3"
resolved "https://npm.gvia.group/mongodb/-/mongodb-3.
1.13.tgz#f8cdcbb36ad7a08b570bd1271c8525753f75f9f4
"
integrity sha512-
sz2dhvBZQWf3LRNDhbd30KHVzdjZx9IKC0L+kSZ/gzYquCF5zPOgGqRz6sSCqYZtKP2ekB4nfLxhGtzGHnIKxA
==
mongodb@^3.
2.
3:
version "3.
2.
3"
resolved "https://npm.gvia.group/mongodb/-/mongodb-3.
2.3.tgz#4610ee33d300caa74329c2dd03e137210723cd91
"
integrity sha512-
jw8UyPsq4QleZ9z+t/pIVy3L++51vKdaJ2Q/XXeYxk/3cnKioAH8H6f5tkkDivrQL4PUgUOHe9uZzkpRFH1XtQ
==
dependencies:
mongodb-core "
3.1.11
"
mongodb-core "
^3.2.3
"
safe-buffer "^5.1.2"
ms@2.0.0:
...
...
@@ -1274,12 +1274,12 @@ node-pre-gyp@^0.10.0:
semver "^5.3.0"
tar "^4"
nodemon@^1.18.
9
:
version "1.18.
9
"
resolved "https://npm.gvia.group/nodemon/-/nodemon-1.18.
9.tgz#90b467efd3b3c81b9453380aeb2a2cba535d0ead
"
integrity sha512-
oj/eEVTEI47pzYAjGkpcNw0xYwTl4XSTUQv2NPQI6PpN3b75PhpuYk3Vb3U80xHCyM2Jm+1j68ULHXl4OR3Af
w==
nodemon@^1.18.
11
:
version "1.18.
11
"
resolved "https://npm.gvia.group/nodemon/-/nodemon-1.18.
11.tgz#d836ab663776e7995570b963da5bfc807e53f6b8
"
integrity sha512-
KdN3tm1zkarlqNo4+W9raU3ihM4H15MVMSE/f9rYDZmFgDHAfAJsomYrHhApAkuUemYjFyEeXlpCOQ2v5gtBE
w==
dependencies:
chokidar "^2.
0.4
"
chokidar "^2.
1.5
"
debug "^3.1.0"
ignore-by-default "^1.0.1"
minimatch "^3.0.4"
...
...
@@ -1995,10 +1995,10 @@ unzip-response@^2.0.1:
resolved "https://npm.gvia.group/unzip-response/-/unzip-response-2.0.1.tgz#d2f0f737d16b0615e72a6935ed04214572d56f97"
integrity sha1-0vD3N9FrBhXnKmk17QQhRXLVb5c=
upath@^1.1.
0
:
version "1.1.
0
"
resolved "https://npm.gvia.group/upath/-/upath-1.1.
0.tgz#35256597e46a581db4793d0ce47fa9aebfc9fabd
"
integrity sha512-
bzpH/oBhoS/QI/YtbkqCg6VEiPYjSZtrHQM6/QnJS6OL9pKUFLqb3aFh4Scvwm45+7iAgiMkLhSbaZxUqmrprw
==
upath@^1.1.
1
:
version "1.1.
2
"
resolved "https://npm.gvia.group/upath/-/upath-1.1.
2.tgz#3db658600edaeeccbe6db5e684d67ee8c2acd068
"
integrity sha512-
kXpym8nmDmlCBr7nKdIx8P2jNBa+pBpIUFRnKJ4dr8htyYGJFokkr2ZvERRtUN+9SY+JqXouNgUPtv6JQva/2Q
==
update-notifier@^2.5.0:
version "2.5.0"
...
...
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