diff --git a/middleware/shorten.js b/middleware/shorten.js index 46a5262..7c02ff3 100644 --- a/middleware/shorten.js +++ b/middleware/shorten.js @@ -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); diff --git a/package.json b/package.json index 300ad37..7e7eb47 100644 --- a/package.json +++ b/package.json @@ -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",