I have multiple domains example.com and example.nl
I want to make redirect from example.nl to example.com/nl
But I can't see real domain name, because I get us-central1-example-name.cloudfunctions.net
in req.hostname
The function is:
const functions = require('firebase-functions')
const express = require('express')
const app = express()
app.get("*", (req, res) => {
if(req.hostname == 'example.nl'){
return res.status(302).redirect("https://example.com/nl");
}
return res.status(200).send('Hello');
})
exports.nuxtApp = functions.https.onRequest(app)
I couldn't find any instruction how to do it in firebase hosting documentation
UPD: I've found solution. (req.headers['x-forwarded-host'])
const functions = require('firebase-functions')
const express = require('express')
const app = express()
app.get("*", (req, res) => {
if(req.headers['x-forwarded-host'] == 'example.nl'){
return res.status(302).redirect("https://example.com/nl");
}
return res.status(200).send('Hello');
})
exports.nuxtApp = functions.https.onRequest(app)
req.headers["x-forwarded-host"] - this worked for me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With