forked from konklone/shaaaaaaaaaaaaa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.js
35 lines (23 loc) · 875 Bytes
/
routes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var shaaa = require("./shaaa");
module.exports = function(app) {
app.get('/', function(req, res) {
res.render("index.html", {domain: null});
});
app.get('/check/:domain', function(req, res) {
// TODO: sanitize domain for JS
var domain = req.params.domain;
res.render("index.html", {domain: domain});
});
app.get('/api/check/:domain', function(req, res) {
var domain = req.params.domain;
if (!domain) return res.status(500);
// domain gets strictly sanitized in the lib, but can do
// some stuff here too
var escaped = domain.replace(/^https?:\/\//i, '');
console.log("Checking domain: " + domain + ", " + escaped);
shaaa.from(domain, function(err, algorithm, good) {
if (err) return res.status(400).send({error: err});
res.send({algorithm: algorithm, good: good, domain: escaped});
})
});
};