Skip to content

Commit

Permalink
Redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
kennedyrose committed May 19, 2020
1 parent e66e169 commit 58eda5e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/director/src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = async function build(options){
let paths = getPaths(options)
for (let i = paths.length; i--;) {
let path = paths[i]
if (!path.src) continue
let src = join(cwd, options.src, path.src)
let dist = join(cwd, options.dist, path.url || path.dist)
let err = await ncp(src, dist)
Expand Down
27 changes: 18 additions & 9 deletions packages/director/src/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,24 @@ module.exports = function startServer(options){

paths.forEach(path => {
if (path.port) {
app.use(path.url, proxy({
target: `http://localhost:${path.port}`,
changeOrigin: true,
pathRewrite: {
[path.url]: ``,
},
...options.proxyOptions,
...path.proxyOptions,
}))
// Proxy
if (!path.redirect) {
app.use(path.url, proxy({
target: `http://localhost:${path.port}`,
changeOrigin: true,
pathRewrite: {
[path.url]: ``,
},
...options.proxyOptions,
...path.proxyOptions,
}))
}
// Redirect
else{
app.get(path.url, function (req, res) {
res.redirect(`http://localhost:${path.port}`)
})
}
}
else{
let staticDir = join(process.cwd(), options.src, path.src)
Expand Down
4 changes: 4 additions & 0 deletions packages/sandbox-director/director.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Director({
'/assets': {
src: `sandbox-b/www`,
},
'/google': {
port: 3333,
redirect: true,
},
},
src: `../`,
dist: `dist`,
Expand Down

0 comments on commit 58eda5e

Please sign in to comment.