Handle unknown routes
This commit is contained in:
parent
6d6235d267
commit
5e5d76d8fb
38
index.js
38
index.js
@ -34,11 +34,22 @@ const getProfileURLs = async handle => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
server.use(restify.plugins.queryParser());
|
const handleResponse = (profileURLs, req, res) => {
|
||||||
|
if (req.getContentType() === 'application/json') {
|
||||||
|
return res.send(profileURLs);
|
||||||
|
} else {
|
||||||
|
const imageURL = profileURLs[req.query.size] || profileURLs.original;
|
||||||
|
|
||||||
// Handle some stuff we dont have
|
request
|
||||||
server.get('favicon.ico', (req, res) => res.send(404));
|
.get(imageURL)
|
||||||
server.get('sw.js', (req, res) => res.send(404));
|
.on('error', function(err) {
|
||||||
|
console.log(err);
|
||||||
|
})
|
||||||
|
.pipe(res);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
server.use(restify.plugins.queryParser());
|
||||||
|
|
||||||
server.get('/:handle', async function (req, res) {
|
server.get('/:handle', async function (req, res) {
|
||||||
if (!req.params.handle) {
|
if (!req.params.handle) {
|
||||||
@ -55,18 +66,15 @@ server.get('/:handle', async function (req, res) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.getContentType() === 'application/json') {
|
return handleResponse(profileURLs, req, res);
|
||||||
return res.send(profileURLs);
|
});
|
||||||
} else {
|
|
||||||
const imageURL = profileURLs[req.query.size] || profileURLs.original;
|
|
||||||
|
|
||||||
request
|
server.get('/.+', function (req, res) {
|
||||||
.get(imageURL)
|
let profileURLs = {
|
||||||
.on('error', function(err) {
|
original: 'https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png'
|
||||||
console.log(err);
|
};
|
||||||
})
|
|
||||||
.pipe(res);
|
return handleResponse(profileURLs, req, res);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen(process.env.PORT || 9090, function () {
|
server.listen(process.env.PORT || 9090, function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user