I have set up grunt connect like this:
connect: {
options: {
port: 9000,
livereload: 35729,
hostname: 'localhost'
},
livereload: {
options: {
open: true,
base: [
'app'
]
}
}
}
That works great - loads my index.html page as:
http://localhost:9000
However, to keep this consistent with how it will be loaded in production, I would like it to load it with additional context path added, like:
http://localhost:9000/myappcontext/secured
Can this be done simply with grunt-contrib-connect? Or do I need to add some other proxy/middleware?
Anyone got a simple example of this type of set-up?
You can use Rewrite middleware rules to load from a different context-root https://github.com/viart/http-rewrite-middleware
This would work in your scenario:
var rewriteModule = require('http-rewrite-middleware');
middlewares.push(rewriteModule.getMiddleware([
//Load App under context-root of 'myappcontext/secured'
{from: '^/myappcontext/secured(.*)$', to: '/$1'},
//Redirect slash to myappcontext/secured as convenience
{from: '^/$', to: '/myappcontext/secured', redirect: 'permanent'},
//Send a 404 for anything else
{from: '^/.+$', to: '/404'}
]));
Yes you can do this without much trouble, just configure the open
option:
connect: {
options: {
port: 9000,
livereload: 35729,
hostname: 'localhost'
},
livereload: {
options: {
open: {
target: 'http://localhost:9000/myappcontext/secured'
},
base: [
'app'
]
}
}
}
You can consult the README for more information about the available options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With