From f39464ad8ccc6ce1d07580e4b3e61ecb021f8035 Mon Sep 17 00:00:00 2001 From: Damillora Date: Sat, 25 Jul 2020 08:06:44 +0200 Subject: [PATCH] Switch link expansion method --- middleware/shorten.js | 10 ++++++---- package.json | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) 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",