Open
Description
I'd like to add the ability to stop a currently-running server. I propose that:
- the plugin keeps a cache of running server instances by target name
- if the
stop
flag is specified and a server with the same target has been started, it will be stopped and removed from the cache - this behavior will happen automatically before the task starts a server (by default, disableable with an option)
// Stopping a server explicitly.
grunt.registerTask('do_something', ['connect:dev', 'something', 'connect:dev:stop']);
// Stopping a server implicitly (there would be "port in use" error here).
grunt.registerTask('do_something', ['connect:dev', 'something']);
grunt.registerTask('do_something_else', ['connect:dev', 'something_else']);
grunt.registerTask('do_everything', ['do_something', 'do_something_else']);
Additionally, I'd like to consider this:
- in addition to a server-by-target cache, what if there is also a server-by-port cache, so that if you start a second server on the same port, it will kill whatever was running before it (by default, disableable with an option) before the task starts?
// Stopping a server by port, not target (dev and prod servers have the same port).
grunt.registerTask('do_something', ['connect:dev', 'something']);
grunt.registerTask('do_something_else', ['do_something', 'something_else', 'connect:prod']);
My use-case:
Let's say I need to run my dev server when I do my integration tests:
grunt.registerTask('test-integration', ['connect:dev', 'mochaTest']);
And let's say both my dev
and prod
server use the same port, but have otherwise different configuration.
grunt.initConfig({
connect: {
options: {
port: 8000,
},
dev: {
options: {
base: ['prod', '.'].
}
},
prod: {
options: {
keepalive: true,
base: ['prod'].
}
}
}
})
What happens when I want to run my integration tests before doing my production build, which includes starting the prod
web server?
grunt.registerTask('prod', ['test-integration', 'build_tasks', 'connect:prod']);
Because I haven't stopped the dev server (because I can't) at the end of test-integration
, the prod
server can't run because the port is already in use. And it's not practical to change the port between the two just to work around this issue.
Thoughts?