We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi all, I want to customize http://localhost:3000/api/ to http://api.example/api/. I've referenced https://github.com/zeit/next.js/tree/canary/examples/with-custom-reverse-proxy but it does not work on getInitialProps.
// server.js const next = require('next'); const routes = require('./routes'); const proxyMiddleware = require('http-proxy-middleware'); const devProxy = { '/api/**': { target: 'http://api.example/', changeOrigin: true, } }; const port = 3000; const dev = process.env.NODE_ENV !== 'production'; const app = next({dir: '.', dev}); const handle = routes.getRequestHandler(app); const express = require('express'); app.prepare() .then(() => { const server = express(); if (dev && devProxy) { Object.keys(devProxy).forEach(function (context) { server.use(proxyMiddleware(context, devProxy[context])) }); } server.all('*', (req, res) => handle(req, res)); server.listen(port, (err) => { if (err) throw err; console.log(`> Ready on http://localhost:${port}`) }) }) .catch(err => { console.log('An error occurred, unable to start the server'); console.log(err); }) ;
Thanks!
The text was updated successfully, but these errors were encountered:
Questions should be posted on https://spectrum.chat/next-js.
Sorry, something went wrong.
No branches or pull requests
Hi all,
I want to customize http://localhost:3000/api/ to http://api.example/api/. I've referenced https://github.com/zeit/next.js/tree/canary/examples/with-custom-reverse-proxy but it does not work on getInitialProps.
Thanks!
The text was updated successfully, but these errors were encountered: