This repository has been archived by the owner on Apr 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Simplify proxy addon example * Undo proxy.config.js changes, add spa-with-api-simple.config.js
- Loading branch information
1 parent
43205c2
commit 67c1050
Showing
2 changed files
with
38 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
|
||
const history = require('connect-history-api-fallback'); | ||
const proxy = require('http-proxy-middleware'); | ||
const convert = require('koa-connect'); | ||
|
||
module.exports = { | ||
entry: { | ||
index: [path.resolve(__dirname, 'app.js')] | ||
}, | ||
mode: 'development', | ||
output: { | ||
filename: 'output.js' | ||
} | ||
}; | ||
|
||
module.exports.serve = { | ||
content: [__dirname], | ||
add: (app, middleware, options) => { | ||
app.use(convert(proxy('/api', { target: 'http://localhost:8081' }))); | ||
app.use(convert(history())); | ||
} | ||
}; | ||
|
||
// This add-on will route all incoming requests for | ||
// "http://localhost:8080/api/*" to "http://localhost:8081/api/*" (note the port | ||
// change), and all remaining requests, which would otherwise result in 404, | ||
// will be rewritten to serve your "index.html", which is useful for single-page | ||
// applications. | ||
// | ||
// To remove the "/api" prefix when proxying the API requests, just add | ||
// "pathRewrite: { '^/api': '' }" to proxy's options. | ||
// | ||
// Proxy's docs: https://github.com/chimurai/http-proxy-middleware | ||
// Fallback's docs: https://github.com/bripkens/connect-history-api-fallback |