-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nextjs) : add proxy configuration support (#2407)
* feat(nextjs): add proxy configuration support ISSUES CLOSED: #2011 * chore(bazel): disable recalcitrant bazel e2e tests for now
- Loading branch information
1 parent
305cd42
commit e64f66c
Showing
11 changed files
with
197 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './src/utils/types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/next/src/builders/dev-server/lib/custom-server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import NextServer from 'next/dist/server/next-dev-server'; | ||
import * as path from 'path'; | ||
import { NextServerOptions, ProxyConfig } from '../../../utils/types'; | ||
|
||
export function customServer( | ||
settings: NextServerOptions, | ||
proxyConfig?: ProxyConfig | ||
) { | ||
const nextApp = new NextServer(settings); | ||
|
||
return require(path.resolve(settings.dir, settings.path))( | ||
nextApp, | ||
settings, | ||
proxyConfig | ||
); | ||
} |
32 changes: 32 additions & 0 deletions
32
packages/next/src/builders/dev-server/lib/default-server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import * as express from 'express'; | ||
import next from 'next'; | ||
import { NextServerOptions, ProxyConfig } from '../../../utils/types'; | ||
|
||
/** | ||
* Adapted from https://github.com/zeit/next.js/blob/master/examples/with-custom-reverse-proxy/server.js | ||
* @param settings | ||
*/ | ||
export async function defaultServer( | ||
settings: NextServerOptions, | ||
proxyConfig?: ProxyConfig | ||
): Promise<void> { | ||
const app = next(settings); | ||
const handle = app.getRequestHandler(); | ||
|
||
await app.prepare(); | ||
|
||
const server: express.Express = express(); | ||
|
||
// Set up the proxy. | ||
if (proxyConfig) { | ||
const proxyMiddleware = require('http-proxy-middleware'); | ||
Object.keys(proxyConfig).forEach(context => { | ||
server.use(proxyMiddleware(context, proxyConfig[context])); | ||
}); | ||
} | ||
|
||
// Default catch-all handler to allow Next.js to handle all other routes | ||
server.all('*', (req, res) => handle(req, res)); | ||
|
||
server.listen(settings.port, settings.hostname); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.