{"action":"created","issue":{"url":"https://api.github.com/repos/webpack/webpack/issues/323","labels_url":"https://api.github.com/repos/webpack/webpack/issues/323/labels{/name}","comments_url":"https://api.github.com/repos/webpack/webpack/issues/323/comments","events_url":"https://api.github.com/repos/webpack/webpack/issues/323/events","html_url":"https://github.com/webpack/webpack/issues/323","id":36339309,"number":323,"title":"Injecting middle-ware into the webpack-dev-server?","user":{"login":"ootz0rz","id":510046,"avatar_url":"https://avatars.githubusercontent.com/u/510046?v=3","gravatar_id":"","url":"https://api.github.com/users/ootz0rz","html_url":"https://github.com/ootz0rz","followers_url":"https://api.github.com/users/ootz0rz/followers","following_url":"https://api.github.com/users/ootz0rz/following{/other_user}","gists_url":"https://api.github.com/users/ootz0rz/gists{/gist_id}","starred_url":"https://api.github.com/users/ootz0rz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ootz0rz/subscriptions","organizations_url":"https://api.github.com/users/ootz0rz/orgs","repos_url":"https://api.github.com/users/ootz0rz/repos","events_url":"https://api.github.com/users/ootz0rz/events{/privacy}","received_events_url":"https://api.github.com/users/ootz0rz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2014-06-23T22:58:54Z","updated_at":"2015-01-07T00:12:31Z","closed_at":null,"body":"In my normal server using grunt-connect, I can do this fairly easily doing something like:\r\n\r\n```js\r\n    connect: {\r\n      options: {\r\n        port: 8000\r\n      },\r\n\r\n      dist: {\r\n        options: {\r\n          keepalive: false,\r\n          middleware: function (connect, options) {\r\n            var middlewares = [];\r\n\r\n            middlewares.push(modRewrite(modRewriteRulesConfig));\r\n             ... other stuff ....\r\n\r\n            return middlewares;\r\n          }\r\n        }\r\n      }\r\n    },\r\n```\r\n\r\nI want to add the same set of middleware to the dev server, which I currently have defined as:\r\n```js\r\n    'webpack-dev-server': {\r\n      options: {\r\n        port: 8000,\r\n        webpack: webpackDevConfig,\r\n        publicPath: '/scripts/',\r\n        contentBase: './<%= pkg.src %>/',\r\n      },\r\n\r\n      start: {\r\n        keepAlive: true,\r\n      }\r\n    }\r\n```\r\n\r\nIs this possible, if so, how can I go about doing it? Thanks!"},"comment":{"url":"https://api.github.com/repos/webpack/webpack/issues/comments/68958454","html_url":"https://github.com/webpack/webpack/issues/323#issuecomment-68958454","issue_url":"https://api.github.com/repos/webpack/webpack/issues/323","id":68958454,"user":{"login":"grrowl","id":907140,"avatar_url":"https://avatars.githubusercontent.com/u/907140?v=3","gravatar_id":"","url":"https://api.github.com/users/grrowl","html_url":"https://github.com/grrowl","followers_url":"https://api.github.com/users/grrowl/followers","following_url":"https://api.github.com/users/grrowl/following{/other_user}","gists_url":"https://api.github.com/users/grrowl/gists{/gist_id}","starred_url":"https://api.github.com/users/grrowl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grrowl/subscriptions","organizations_url":"https://api.github.com/users/grrowl/orgs","repos_url":"https://api.github.com/users/grrowl/repos","events_url":"https://api.github.com/users/grrowl/events{/privacy}","received_events_url":"https://api.github.com/users/grrowl/received_events","type":"User","site_admin":false},"created_at":"2015-01-07T00:12:31Z","updated_at":"2015-01-07T00:12:31Z","body":"The above solution is really gross. Use https://github.com/webpack/webpack-dev-middleware, then (this is using grunt):\r\n\r\n```js\r\nconnect: {\r\n  options: {\r\n    hostname: '*'\r\n    port: 80,\r\n\r\n    middleware: function(connect, options) {\r\n      return [\r\n        // handles existing files within src directory\r\n        connect.static(contentBase),\r\n\r\n        // connect.directory(contentBase),\r\n        require('serve-index')(contentBase),\r\n\r\n        // route other files to webpack's in-memory dev server\r\n        webpackMiddleware(webpack(webpackConfig))\r\n      ];\r\n    }\r\n  }\r\n}\r\n```"}}