2020-07-25 06:06:44 +00:00
|
|
|
const fetch = require('node-fetch');
|
2019-09-27 19:49:30 +00:00
|
|
|
|
|
|
|
export default function (context) {
|
2020-07-25 06:06:44 +00:00
|
|
|
return fetch(process.env.SHORTENER_BASE+context.route.path, {
|
|
|
|
redirect: 'manual',
|
|
|
|
}).then(function(res) {
|
|
|
|
var unshortenedUrl = res.headers.get('Location');
|
|
|
|
if(unshortenedUrl == process.env.SHORTENER_BASE+"/") {
|
2019-09-28 11:00:59 +00:00
|
|
|
context.error({ statusCode: 404, message: "The page cannot be found"});
|
|
|
|
} else {
|
|
|
|
context.redirect(unshortenedUrl);
|
2019-09-28 09:45:11 +00:00
|
|
|
}
|
2019-09-27 19:49:30 +00:00
|
|
|
});
|
|
|
|
// context.redirect("https://nanao.moe");
|
|
|
|
}
|