From 28a3c6805c867930e1c68300cdb2759afe98a37e Mon Sep 17 00:00:00 2001 From: EIlif Johansen Date: Wed, 19 Jun 2024 09:51:59 +0200 Subject: [PATCH] La til url path --- Dockerfile | 2 +- index.js | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 61de00d..257fb75 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ RUN yarn add dotenv RUN yarn add axios RUN yarn add cors -EXPOSE 8081 +EXPOSE 8080 COPY index.js /app/ COPY /config/. /app/config/. diff --git a/index.js b/index.js index bbecffc..9523344 100644 --- a/index.js +++ b/index.js @@ -215,14 +215,23 @@ const fetchAmplitudeJsonData = (url, options, proxyResponse) => { }); } -app.get('/getnav', (req, res) => { - axios.get('https://www.nav.no/') +app.get('/url/*', (req, res) => { + // Decode the URL component + let urlToFetch = decodeURIComponent(req.params[0]); + + // Check if the URL starts with http:// or https:// + if (!urlToFetch.match(/^https?:\/\//)) { + urlToFetch = 'http://' + urlToFetch; + } + + // Perform the GET request to the extracted URL + axios.get(urlToFetch) .then(response => { res.send(response.data); }) .catch(error => { console.error(error); - res.status(500).send('Error occurred while fetching data from nav.no'); + res.status(500).send(`Error occurred while fetching data from ${urlToFetch}`); }); }); @@ -240,6 +249,6 @@ app.get("/isAlive", (req, res) => res.sendStatus(200)); app.get("/isReady", (req, res) => res.sendStatus(200)); app.get("/", (req, res) => res.sendStatus(200)); -app.listen(8081, function () { - console.log("Express Started on Port 8081"); +app.listen(8080, function () { + console.log("Express Started"); });