Skip to content

Commit

Permalink
La til url path
Browse files Browse the repository at this point in the history
  • Loading branch information
eilifjohansen committed Jun 19, 2024
1 parent 4c0b83a commit 28a3c68
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/.
Expand Down
19 changes: 14 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
});
});

Expand All @@ -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");
});

0 comments on commit 28a3c68

Please sign in to comment.