Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scanner
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
whats-this
scanner
Commits
dc0fbe78
Commit
dc0fbe78
authored
8 years ago
by
aurieh
Browse files
Options
Downloads
Patches
Plain Diff
Rewrite index, freshclam
parent
087b492a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
index.js
+25
-20
25 additions, 20 deletions
index.js
routes/freshclam.js
+8
-4
8 additions, 4 deletions
routes/freshclam.js
with
33 additions
and
24 deletions
index.js
+
25
−
20
View file @
dc0fbe78
// Required modules
// Required modules
const
express
=
require
(
'
express
'
);
const
koa
=
require
(
'
koa
'
);
// Check for required environment variables
// Check for required environment variables
for
(
let
env
of
[
for
(
let
env
of
[
...
@@ -13,39 +13,44 @@ for (let env of [
...
@@ -13,39 +13,44 @@ for (let env of [
}
}
}
}
// Create Express app
// Create Koa app
const
app
=
express
();
const
app
=
koa
();
app
.
disable
(
'
x-powered-by
'
);
const
route
=
require
(
"
koa-route
"
);
app
.
disable
(
'
etag
'
);
/**
/**
* Parse request body.
* Parse request body.
*/
*/
app
.
use
(
(
req
,
res
,
next
)
=>
{
app
.
use
(
next
=>
{
if
(
req
.
method
===
'
GET
'
||
req
.
method
===
'
DELETE
'
)
{
if
(
req
.
method
===
'
GET
'
||
req
.
method
===
'
DELETE
'
)
{
return
next
();
yield
next
;
return
;
}
}
if
(
!
req
.
is
(
'
application/json
'
))
{
if
(
!
this
.
headers
[
'
application/json
'
])
{
return
res
.
status
(
400
).
json
({
this
.
status
=
400
;
this
.
body
=
{
code
:
400
,
code
:
400
,
message
:
'
invalid content type, should be application/json
'
message
:
'
invalid content type, should be application/json
'
});
};
yield
next
;
return
;
}
}
let
rawData
=
''
;
let
rawData
=
''
;
req
.
on
(
'
data
'
,
chunk
=>
{
this
.
req
.
on
(
'
data
'
,
chunk
=>
{
rawData
+=
chunk
.
toString
();
rawData
+=
chunk
.
toString
();
});
});
req
.
on
(
'
end
'
,
()
=>
{
this
.
req
.
on
(
'
end
'
,
()
=>
{
try
{
try
{
req
.
body
=
JSON
.
parse
(
rawData
);
this
.
req
.
body
=
JSON
.
parse
(
rawData
);
next
();
yield
next
;
return
;
}
catch
(
err
)
{
}
catch
(
err
)
{
res
.
status
(
400
).
json
(
{
this
.
body
=
{
code
:
400
,
code
:
400
,
message
:
'
invalid body data, should be a valid JSON string
'
message
:
'
invalid body data, should be a valid JSON string
'
});
};
this
.
status
=
400
;
}
}
});
});
});
});
...
@@ -54,22 +59,22 @@ app.use((req, res, next) => {
...
@@ -54,22 +59,22 @@ app.use((req, res, next) => {
* POST /scan
* POST /scan
* Scan the file specified in the S3 event in the body.
* Scan the file specified in the S3 event in the body.
*/
*/
app
.
post
(
'
/scan
'
,
require
(
'
./routes/scan.js
'
));
app
.
use
(
route
.
post
(
'
/scan
'
,
require
(
'
./routes/scan.js
'
))
)
;
/**
/**
* GET /freshclam
* GET /freshclam
* Run freshclam to update the virus database.
* Run freshclam to update the virus database.
*/
*/
app
.
get
(
'
/freshclam
'
,
require
(
'
./routes/freshclam.js
'
));
app
.
use
(
route
.
get
(
'
/freshclam
'
,
require
(
'
./routes/freshclam.js
'
))
)
;
/**
/**
* GET /health
* GET /health
* Return a 200 OK response, so that Elastic Beanstalk can check if the server
* Return a 200 OK response, so that Elastic Beanstalk can check if the server
* is still online.
* is still online.
*/
*/
app
.
get
(
'
/health
'
,
(
req
,
res
,
next
)
=>
{
app
.
use
(
route
.
get
(
'
/health
'
,
(
req
,
res
,
next
)
=>
{
res
.
status
(
200
).
end
();
res
.
status
(
200
).
end
();
});
})
)
;
// Listen on 8080
// Listen on 8080
app
.
listen
(
8080
);
app
.
listen
(
8080
);
This diff is collapsed.
Click to expand it.
routes/freshclam.js
+
8
−
4
View file @
dc0fbe78
...
@@ -5,12 +5,16 @@ const freshClam = require('../lib/freshclam.js');
...
@@ -5,12 +5,16 @@ const freshClam = require('../lib/freshclam.js');
* > GET /freshclam
* > GET /freshclam
* Run freshclam to update the virus database.
* Run freshclam to update the virus database.
*/
*/
module
.
exports
=
function
freshclam
(
req
,
res
,
next
)
{
module
.
exports
=
function
*
freshclam
(
next
)
{
freshClam
().
then
(()
=>
{
freshClam
().
then
(()
=>
{
res
.
status
(
200
).
end
();
this
.
body
=
null
;
this
.
status
=
200
;
yield
;
}).
catch
(
err
=>
{
}).
catch
(
err
=>
{
console
.
error
(
'
failed to update virus definitions
'
);
console
.
error
(
'
failed to update virus definitions
'
);
console
.
error
(
err
);
console
.
error
(
err
);
res
.
status
(
500
).
end
();
this
.
body
=
null
;
this
.
status
=
500
;
yield
;
});
});
}
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment