{"name":"grunt-contrib-connect","version":"5.0.1","keywords":["gruntplugin","server","connect","http"],"author":{"url":"https://gruntjs.com/","name":"Grunt Team"},"license":"MIT","_id":"grunt-contrib-connect@5.0.1","maintainers":[{"name":"cowboy","email":"cowboy@rj3.net"},{"name":"jmeas","email":"roaster.karmic_0r@icloud.com"},{"name":"tkellen","email":"tyler@sleekcode.net"},{"name":"vladikoff","email":"vlad@vladikoff.com"},{"name":"shama","email":"kyle@dontkry.com"},{"name":"xhmikosr","email":"xhmikosr@gmail.com"}],"contributors":[{"url":"http://benalman.com","name":"\"Cowboy\" Ben Alman"},{"url":"http://goingslowly.com","name":"Tyler Kellen"},{"url":"http://sindresorhus.com","name":"Sindre Sorhus"},{"name":"Kyle Robinson Young"},{"name":"Jared Stehler"},{"name":"Vlad Filippov"},{"name":"Stepan Stolyarov"},{"name":"Samori Gorse"},{"name":"Nicolas Gryman"},{"name":"Lachèze Alexandre"},{"name":"Jubal Mabaquiao"},{"name":"Eddie Monge Jr"},{"name":"Christopher Joslyn"},{"name":"Ates Goral"},{"name":"Alex Treppass"},{"name":"Aaron Lampros"},{"name":"Philipp Söhnlein"}],"homepage":"https://github.com/gruntjs/grunt-contrib-connect#readme","bugs":{"url":"https://github.com/gruntjs/grunt-contrib-connect/issues"},"dist":{"shasum":"c8cc828a3c806520d9126377870b62eeb8bd2f92","tarball":"http://registry-npm.ywwl.com/grunt-contrib-connect/download/grunt-contrib-connect-5.0.1.tgz","fileCount":11,"integrity":"sha512-Hfq/0QJl3ddD2N/a/1cDJHkKEOGk6m7W6uxNe0AmYwtf6v0F/4+8q9rvPJ1tl+mrI90lU/89I9T/h48qqeMfQA==","signatures":[{"sig":"MEUCIQDj0qGGZG2wvAzT91PE4m4TK8bFB7q+CUiTRRJ0wRLiAwIgY/f/SAM2hfqiP6MwF8snaQjUv6TmC/IvF75Cy/DFpvs=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":34949,"size":14326,"noattachment":false,"key":"/grunt-contrib-connect/-/grunt-contrib-connect-5.0.1.tgz"},"main":"tasks/connect.js","engines":{"node":">=16"},"gitHead":"9d9b2951cfc62945eb9b25e18e3e23bc870a6af6","scripts":{"test":"grunt test"},"_npmUser":{"name":"vladikoff","email":"vlad@vladikoff.com"},"repository":{"url":"git+https://github.com/gruntjs/grunt-contrib-connect.git","type":"git"},"_npmVersion":"10.7.0","description":"Start a connect web server","directories":{},"_nodeVersion":"20.15.1","dependencies":{"open":"^8.0.0","async":"^3.2.5","morgan":"^1.10.0","connect":"^3.7.0","portscanner":"^2.2.0","serve-index":"^1.9.1","serve-static":"^1.15.0","http2-wrapper":"^2.2.1","connect-livereload":"^0.6.1"},"_hasShrinkwrap":false,"devDependencies":{"grunt":"^1.6.1","grunt-contrib-jshint":"^3.2.0","grunt-contrib-internal":"^9.0.0","grunt-contrib-nodeunit":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/grunt-contrib-connect_5.0.1_1728562517694_0.3984534972852454","host":"s3://npm-registry-packages"},"readme":"# grunt-contrib-connect v5.0.1 [![Build Status](https://github.com/gruntjs/grunt-contrib-connect/workflows/Tests/badge.svg)](https://github.com/gruntjs/grunt-contrib-connect/actions?workflow=Tests)\n\n> Start a connect web server\n\n\n\n## Getting Started\n\nIf you haven't used [Grunt](https://gruntjs.com/) before, be sure to check out the [Getting Started](https://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](https://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:\n\n```shell\nnpm install grunt-contrib-connect --save-dev\n```\n\nOnce the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:\n\n```js\ngrunt.loadNpmTasks('grunt-contrib-connect');\n```\n\n\n\n\n## Connect task\n_Run this task with the `grunt connect` command._\n\nNote that this server only runs as long as grunt is running. Once grunt's tasks have completed, the web server stops. This behavior can be changed with the [keepalive](#keepalive) option, and can be enabled ad-hoc by running the task like `grunt connect:keepalive`.\n\nThis task was designed to be used in conjunction with another task that is run immediately afterwards, like the [grunt-contrib-qunit plugin](https://github.com/gruntjs/grunt-contrib-qunit) `qunit` task.\n### Options\n\n#### port\nType: `Integer`  \nDefault: `8000`\n\nThe port on which the webserver will respond. The task will fail if the specified port is already in use (unless [useAvailablePort](#useavailableport) is set). You can use the special values `0` or `'?'` to use a system-assigned port.\n\n#### protocol\nType: `String`  \nDefault: `'http'`\n\nMay be `'http'`, `'http2'` or `'https'`.\n\n#### hostname\nType: `String`  \nDefault: `'0.0.0.0'`\n\nThe hostname on which the webserver can be accessed.\n\nSetting it to `'*'`, like '`0.0.0.0`', will make the server accessible from any **local** IPv4 address like  `'127.0.0.1'` and the IP assigned to an ethernet or wireless interface (like `'192.168.0.x'` or `'10.0.0.x'`). [More info](https://en.wikipedia.org/wiki/0.0.0.0)\n\nIf [`open`](#open) is set to `true`, the `hostname` setting will be used to generate the URL that is opened by the browser, defaulting to `localhost` if a wildcard hostname was specified.\n\n#### base\nType: `String` or `Array` or `Object`  \nDefault: `'.'`\n\n| Type     | Result                                                                                                                                           | Example                                              |\n| ---      | :---                                                                                                                                             | ---                                                  |\n| *String* | The base (or root) directory from which files will be served. Defaults to the project Gruntfile's directory.                                     | `'public'`                                           |\n| *Array*  | Array of `String` (or `Object`) bases to serve multiple directories. The last base given will be the [directory][] to become browse-able.        | `['public','www-root']`                              |\n| *Object* | Map containing `path` and `options` keys. `options` are passed on to the [serve-static](https://www.npmjs.com/package/serve-static) module. | `{ path: 'public', options: { maxAge: 1000*60*5 } }` |\n\n\n#### directory\nType: `String`  \nDefault: `null`\n\nSet to the directory you wish to be browse-able. Used to override the `base` option browse-able directory.\n\nSee https://www.npmjs.com/package/serve-index for details.\n\n#### keepalive\nType: `Boolean`  \nDefault: `false`\n\nKeep the server alive indefinitely. Note that if this option is enabled, any tasks specified after this task will _never run_. By default, once grunt's tasks have completed, the web server stops. This option changes that behavior.\n\nThis option can also be enabled ad-hoc by running the task like `grunt connect:targetname:keepalive`\n\n#### debug\nType: `Boolean`  \nDefault: `false`\n\nSet the `debug` option to true to enable logging instead of using the `--debug` flag.\n\n#### livereload\nType: `Boolean`, `Number`, or `Object`  \nDefault: `false`\n\nSet to anything but `false` to inject a live reload script tag into your page using [connect-livereload](https://github.com/intesso/connect-livereload).\n\nIf you set to `true`, defaults are used. If you set to a number, that number is used as a port number, together with the hostname you configured. If you set this to an object, that object is passed to `connect-livereload` unchanged as its configuration.\n\n*This does not by itself perform live reloading.* It is intended to be used in tandem with grunt-contrib-watch or another task that will trigger a live reload server upon files changing.\n\n#### open\nType: `Boolean` or `String` or `Object`  \nDefault: `false`\n\nOpen the served page in your default browser.\n\nThis can be one of the following:\n\n- Specifying `true` opens the default server URL (generated from the [`protocol`](#protocol), [`hostname`](#hostname) and [`port`](#port) settings)\n- Specifying a URL opens that URL\n- Specify an object with the following keys to configure [opn](https://www.npmjs.com/package/opn) directly:\n\n\t```js\n\t{\n\t  target: 'http://localhost:8000', // target url to open\n\t  appName: 'open', // name of the app that opens, ie: open, start, xdg-open\n\t  callback: function() {} // called when the app has opened\n\t}\n\t```\n\nNote that in [v0.9.0](https://github.com/gruntjs/grunt-contrib-connect/releases/tag/v0.9.0) [open](https://www.npmjs.com/package/open) was replaced with [opn](https://www.npmjs.com/package/opn) but the configuration remained the same for backwards compatibility. `target`, `appName` and `callback` are the only supported keys in the config object.\n\n#### useAvailablePort\nType: `Boolean`  \nDefault: `false`\n\nIf `true` the task will look for the next available port after the set `port` option.\n\n#### onCreateServer\nType: `Function` or `Array`  \nDefault: `null`\n\nA function to be called after the server object is created, to allow integrating libraries that need access to connect's server object. A Socket.IO example:\n\n```js\ngrunt.initConfig({\n  connect: {\n    server: {\n      options: {\n        port: 8000,\n        hostname: '*',\n        onCreateServer: function(server, connect, options) {\n          var io = require('socket.io').listen(server);\n          io.sockets.on('connection', function(socket) {\n            // do something with socket\n          });\n        }\n      }\n    }\n  }\n});\n```\n\n#### middleware\nType: `Function` or `Array`  \nDefault: `Array` of connect middlewares that use `options.base` for static files and directory browsing\n\nAs an `Array`:\n\n```js\ngrunt.initConfig({\n  connect: {\n    server: {\n      options: {\n        middleware: [\n          function myMiddleware(req, res, next) {\n            res.end('Hello, world!');\n          }\n        ],\n      },\n    },\n  },\n});\n```\n\nAs a `function`:\n\n```js\ngrunt.initConfig({\n  connect: {\n    server: {\n      options: {\n        middleware: function(connect, options, middlewares) {\n          // inject a custom middleware into the array of default middlewares\n          middlewares.unshift(function(req, res, next) {\n            if (req.url !== '/hello/world') return next();\n\n            res.end('Hello, world from port #' + options.port + '!');\n          });\n\n          return middlewares;\n        },\n      },\n    },\n  },\n});\n```\n\nLets you add in your own Connect middlewares. This option expects a function that returns an array of middlewares. See the [project Gruntfile][] and [project unit tests][] for a usage example.\n\n[project Gruntfile]: Gruntfile.js\n[project unit tests]: test/connect_test.js\n\n### Usage examples\n\n#### Basic Use\nIn this example, `grunt connect` (or more verbosely, `grunt connect:server`) will start a static web server at `http://localhost:9001/`, with its base path set to the `www-root` directory relative to the gruntfile, and any tasks run afterwards will be able to access it.\n\n```js\n// Project configuration.\ngrunt.initConfig({\n  connect: {\n    server: {\n      options: {\n        port: 9001,\n        base: 'www-root'\n      }\n    }\n  }\n});\n```\n\nIf you want your web server to use the default options, just omit the `options` object. You still need to specify a target (`uses_defaults` in this example), but the target's configuration object can otherwise be empty or nonexistent. In this example, `grunt connect` (or more verbosely, `grunt connect:uses_defaults`) will start a static web server using the default options.\n\n```js\n// Project configuration.\ngrunt.initConfig({\n  connect: {\n    uses_defaults: {}\n  }\n});\n```\n\n#### Multiple Servers\nYou can specify multiple servers to be run alone or simultaneously by creating a target for each server. In this example, running either `grunt connect:site1` or `grunt connect:site2` will  start the appropriate web server, but running `grunt connect` will run _both_. Note that any server for which the [keepalive](#keepalive) option is specified will prevent _any_ task or target from running after it.\n\n```js\n// Project configuration.\ngrunt.initConfig({\n  connect: {\n    site1: {\n      options: {\n        port: 9000,\n        base: 'www-roots/site1'\n      }\n    },\n    site2: {\n      options: {\n        port: 9001,\n        base: 'www-roots/site2'\n      }\n    }\n  }\n});\n```\n\n#### Static Options\n\nOptions for the serve-static module. See [serve-static](https://www.npmjs.com/package/serve-static):\n\n```js\ngrunt.initConfig({\n  connect: {\n    server: {\n      options: {\n        port: 8000,\n        base: {\n          path: 'www-root',\n          options: {\n            index: 'somedoc.html',\n            maxAge: 300000\n          }\n        }\n      }\n    }\n  }\n});\n```\n\n\n\n#### \n\n#### Roll Your Own\nLike the [Basic Use](#basic-use) example, this example will start a static web server at `http://localhost:9001/`, with its base path set to the `www-root` directory relative to the gruntfile. Unlike the other example, this is done by creating a brand new task. in fact, this plugin isn't even installed!\n\n```js\n// Project configuration.\ngrunt.initConfig({ /* Nothing needed here! */ });\n\n// After running \"npm install connect serve-static --save-dev\" to add connect as a dev\n// dependency of your project, you can require it in your gruntfile with:\nvar connect = require('connect');\nvar serveStatic = require('serve-static');\nconnect(serveStatic('www-root')).listen(9001);\n\n// Now you can define a \"connect\" task that starts a webserver, using the\n// connect lib, with whatever options and configuration you need:\ngrunt.registerTask('connect', 'Start a custom static web server.', function() {\n  grunt.log.writeln('Starting static web server in \"www-root\" on port 9001.');\n  connect(serveStatic('www-root')).listen(9001);\n});\n```\n\n#### Support for HTTPS / HTTP2\n\nA default certificate authority, certificate and key file are provided and pre-\nconfigured for use when `protocol` has been set to `https`.\n\nNOTE: No passphrase set for the certificate.\nIf you are getting warnings in Google Chrome, add 'server.crt' (from 'node_modules/tasks/certs')\nto your keychain.\nIn OS X, after you add 'server.crt', right click on the certificate,\nselect 'Get Info' - 'Trust' - 'Always Trust', close window, restart Chrome.\n\nFor HTTPS / HTTP2 livereload with [grunt-contrib-watch](https://github.com/gruntjs/grunt-contrib-watch) \n see the last example [here](https://github.com/gruntjs/grunt-contrib-watch#optionslivereload).\n\n###### Advanced HTTPS / HTTP2 config\n\nIf the default certificate setup is unsuitable for your environment, OpenSSL\ncan be used to create a set of self-signed certificates with a local ca root.\n\n```shell\n### Create ca.key, use a password phrase when asked\n### When asked 'Common Name (e.g. server FQDN or YOUR name) []:' use your hostname, i.e 'mysite.dev'\nopenssl genrsa -des3 -out ca.key 1024\nopenssl req -new -key ca.key -out ca.csr\nopenssl x509 -req -days 365 -in ca.csr -out ca.crt -signkey ca.key\n\n### Create server certificate\nopenssl genrsa -des3 -out server.key 1024\nopenssl req -new -key server.key -out server.csr\n\n### Remove password from the certificate\ncp server.key server.key.org\nopenssl rsa -in server.key.org -out server.key\n\n### Generate self-siged certificate\nopenssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt\n```\n\nFor more details on the various options that can be set when configuring SSL,\nplease see the Node documentation for [TLS][].\n\nGrunt configuration would become\n\n```js\n// Project configuration.\ngrunt.initConfig({\n  connect: {\n    server: {\n      options: {\n        protocol: 'https', // or 'http2'\n        port: 8443,\n        key: grunt.file.read('server.key').toString(),\n        cert: grunt.file.read('server.crt').toString(),\n        ca: grunt.file.read('ca.crt').toString()\n      },\n    },\n  },\n});\n```\n\n[TLS]: https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener\n\n#### Grunt Events\nThe connect plugin will emit a grunt event, `connect.{taskName}.listening`, once the server has started. You can listen for this event to run things against a keepalive server, for example:\n\n```js\ngrunt.registerTask('jasmine-server', 'start web server for jasmine tests in browser', function() {\n  grunt.task.run('jasmine:tests:build');\n\n  grunt.event.once('connect.tests.listening', function(host, port) {\n    var specRunnerUrl = 'http://' + host + ':' + port + '/_SpecRunner.html';\n    grunt.log.writeln('Jasmine specs available at: ' + specRunnerUrl);\n    require('open')(specRunnerUrl);\n  });\n\n  grunt.task.run('connect:tests:keepalive');\n});\n```\n\n\n## Release History\n\n * 2024-08-27   v5.0.1   Replace use of deprecated `util.isArray`.\n * 2024-07-05   v5.0.0   Replaced node-http2 with http2-wrapper, potental breaking changes. Bump to deps, serve-static, async and internal grunt\n * 2023-07-13   v4.0.0   Requires node 16+. Updated dependencies.\n * 2020-07-16   v3.0.0   Requires node 10+. Updated dependencies.\n * 2019-09-03   v2.1.0   Update package lock. Allow all configuration options of livereload to be passed through.\n * 2018-09-09   v2.0.0   Drop Node.js < 6 support. Update all dependencies and switch to `node-http2`. Add `secureProtocol` in `httpsOptions`. Fix `open.appName`. Allow passing `serve-index` options.\n * 2016-04-27   v1.0.2   Fixed http2 dependencies and stopped using the fork.\n * 2016-03-22   v1.0.1   Fixed dependencies behind corporate proxy server.\n * 2016-03-04   v1.0.0   Use predefined logger format with colored http status. Update deps and docs. HTTP2 support. Other fixes.\n * 2015-08-03   v0.11.2   Documentation fixes.\n * 2015-08-01   v0.11.1   Fixes debug logging.\n * 2015-07-30   v0.11.0   Update to connect 3.\n * 2015-04-03   v0.10.1   Fixes npm corruption issue.\n * 2015-04-03   v0.10.0   Node.js 0.12 fixes. Doc updates. Fixes port finding. Other fixes.\n * 2014-11-07   v0.9.0   Adds routable middleware. Switch to `opn` as it fixes some Linux issues. Add support for `connect.static` instance options.\n * 2014-06-09   v0.8.0   Update connect and connect-livereload.\n * 2014-02-27   v0.7.1   Fixes issue with the '*' `hostname` option.\n * 2014-02-18   v0.7.0   Update connect to ~2.13.0. Default hostname switched to `0.0.0.0`. Modified `options.middleware` to accept an array or a function.\n * 2013-12-29   v0.6.0   Open `options.hostname` if provided. Update connect-livereload to ~0.3.0. Update connect to ~2.12.0. Use well-formed SSL certificates. Support all options of open. Make directory browseable when base is a string.\n * 2013-09-05   v0.5.0   Add `open` option.\n * 2013-09-05   v0.4.2   Un-normalize `options.base` as it should be a string or an array as the user has set. Fix setting target `hostname` option.\n * 2013-09-02   v0.4.1   Browse-able directory is the last item supplied to bases. Added directory option to override browse-able directory.\n * 2013-09-01   v0.4.0   Fix logging of which server address. Ability to set multiple bases. Event emitted when server starts listening. Support for HTTPS. `debug` option added to display debug logging like the `--debug` flag. `livereload` option added to inject a livereload snippet into the page.\n * 2013-04-10   v0.3.0   Add ability to listen on system-assigned port.\n * 2013-03-07   v0.2.0   Upgrade connect dependency.\n * 2013-02-17   v0.1.2   Ensure Gruntfile.js is included on npm.\n * 2013-02-15   v0.1.1   First official release for Grunt 0.4.0.\n * 2013-01-18   v0.1.1rc6   Updating grunt/gruntplugin dependencies to rc6. Changing in-development grunt/gruntplugin dependency versions from tilde version ranges to specific versions.\n * 2013-01-09   v0.1.1rc5   Updating to work with grunt v0.4.0rc5.\n * 2012-11-01   v0.1.0   Work in progress, not yet officially released.\n\n---\n\nTask submitted by [\"Cowboy\" Ben Alman](http://benalman.com)\n\n*This is a generated file.*\n","publish_time":1728562517948,"_cnpm_publish_time":1728562517948,"dist-tags":{"latest":"5.0.1"}}