Switch link expansion method

This commit is contained in:
Damillora 2020-07-25 08:06:44 +02:00
parent 2574e5a828
commit f39464ad8c
2 changed files with 7 additions and 4 deletions

View File

@ -1,9 +1,11 @@
import { tall } from 'tall';
const fetch = require('node-fetch');
export default function (context) {
return tall(process.env.SHORTENER_BASE+context.route.path).then(function(unshortenedUrl) {
if(unshortenedUrl == process.env.SHORTENER_BASE) {
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+"/") {
context.error({ statusCode: 404, message: "The page cannot be found"});
} else {
context.redirect(unshortenedUrl);

View File

@ -15,6 +15,7 @@
"cross-env": "^5.2.0",
"express": "^4.16.4",
"howler": "^2.1.2",
"node-fetch": "^2.6.0",
"node-sass": "^4.12.0",
"nuxt": "^2.0.0",
"sass-loader": "^8.0.0",