#I can redirect the default Railway domain to the main domain that I have?

8 messages · Page 1 of 1 (latest)

dry parcel
#

I want to set up a redirection for my default domain, for example, domain.up.railway.app ** redirect to ** domain.com.

devout sequoiaBOT
#

Project ID: N/A

fossil terrace
#

You could probably set that up in your code

#
if (req.host == "domain.up.railway.app") res.redirect("domain.com")
dry parcel
#

It didn't work, when I put domain.up.railway.ap the same domain continues to appear, it doesn't change.

fossil terrace
#

that would be an issue with your code

dry parcel
#

My code:

import express from 'express';
import logger from 'morgan';

const app = express();
const port = config.PORT
app.use(express.json());

app.disable('x-powered-by')
app.use(logger('dev'))
app.use(express.static('client-microAngel'));

app.use((req, res, next) => {
if (req.hostname === "clinicamicropigmentacao.up.railway.app") {
console.log("n deu mano.....",req.url);
return res.redirect("https://clinicamicropigmentacao.com" + req.url);
}
next();
console.log("n deu mano.....",req.url);
});

app.get('/', (req, res) => {
res.sendFile(process.cwd() + '/client-microAngel/index.html');
});

app.listen(port, '0.0.0.0', () => {
console.log(Servidor ouvindo na porta ${port});
});

fossil terrace
#

odd, I used the same middleware you used and it worked as expected for me
make sure you don't have other middleware that could be rerouting or blocking requests from propagating to the middleware responsible for redirecting