Skip to content

Instantly share code, notes, and snippets.

@BlazerYoo
Created May 24, 2022 16:06
Show Gist options
  • Save BlazerYoo/4907bfdb214685ad7ccd246b4e66fbc5 to your computer and use it in GitHub Desktop.
Save BlazerYoo/4907bfdb214685ad7ccd246b4e66fbc5 to your computer and use it in GitHub Desktop.
// Credits: https://www.geeksforgeeks.org/how-to-get-the-full-url-in-expressjs/
const express = require('express');
const app = express();
const PORT = 3000;
app.get('*', function (req, res) {
const protocol = req.protocol;
const host = req.hostname;
const url = req.originalUrl;
const port = process.env.PORT || PORT;
const fullUrl = `${protocol}://${host}:${port}${url}`;
const responseString = `Full URL: ${fullUrl}`;
res.send(responseString);
})
app.listen(PORT, (error) => {
if(!error)
console.log("Server running, app listening on port", PORT)
else
console.log("Error:", error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment