Replies: 1 comment 4 replies
-
Where in your server are you doing the redirect? I don't think I saw it. Is it within This has worked for me in the past for redirecting: const app = next({ dev });
const handler = app.getRequestHandler();
app
.prepare()
.then(() => {
const server = express();
server.get('/some-route', (req, res) => {
res.redirect('appbundle://deeplink');
});
// catch-all handler to allow next to handle requests
server.get('*', handler);
server.listen(process.env.PORT, err => {
if (err) throw err;
console.log(
`> Ready on http://localhost:${process.env.PORT}`
);
});
})
.catch(error => {
console.error('Error preparing Next.js app', error);
throw error;
}); |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I have a client app using nextjs("next": "9.1.5") and have implemented it using a custom server which also receives all my react native apps API requests. For deep linking in my react native app I'm using a res.redirect(appbundle://deeplink) but the request is being caught by nextjs and redirecting them to the client web app. I've tried some logic I thought may work in my server.js, please see below, any input is greatly appreciated.
//server.js//
nextApp.prepare().then(() =>{
const app = express();
if(process.env.NODE_ENV === 'development'){
app.use(morgan('dev'));
}
useMiddleware(app)
delegateRoutesFor(app)
app.use(errorHandler)
app.get('*', (req,res,next) =>{
const parsedUrl = parse(req.url, true)
console.log("NEXT",{parsedUrl})
if(parsedUrl.pathname !== '/api/auth/resetpassword'){
return handle(req,res)
}else{
next()
}
})
const PORT = process.env.PORT || 5000;
const server = app.listen(
PORT,
console.log(
Server running ${process.env.NODE_ENV} mode on port ${PORT}
.yellow.bold));
});
Beta Was this translation helpful? Give feedback.
All reactions