Permalink
Browse files

changed logic again, because the old logic was buggy

  • Loading branch information...
1 parent c7b0b34 commit ef8f12a642d88bc83348a9f32017f572ea89f9f8 @sokra sokra committed Jan 9, 2014
Showing with 35 additions and 36 deletions.
  1. +1 −1 bin/webpack-dev-server.js
  2. +1 −1 client/live.js
  3. +4 −4 example/README.md
  4. +28 −29 lib/Server.js
  5. +1 −1 package.json
@@ -54,7 +54,7 @@ if(argv["quiet"])
new Server(webpack(wpOpt), options).listen(argv.port, function(err) {
if(err) throw err;
- console.log("http://localhost:" + argv.port + "/");
+ console.log("http://localhost:" + argv.port + "/webpack-dev-server/");
console.log("webpack result is served from " + options.publicPath);
console.log("content is served from " + options.contentBase);
});
View
@@ -10,7 +10,7 @@ $(function() {
var iframe = $("#iframe");
var hot = false;
- var contentPage = (window.location.pathname) + "__webpack_dev_server" + window.location.search;
+ var contentPage = window.location.pathname.substr("/webpack-dev-server".length) + window.location.search;
status.text("Connecting to socket.io server...");
$errors.hide(); iframe.hide();
View
@@ -2,7 +2,7 @@
``` text
webpack-dev-server --colors
-http://localhost:8080/bundle
+http://localhost:8080/webpack-dev-server/bundle
```
The app should display "It's working" with a dotted background.
@@ -11,7 +11,7 @@ There is no file named `bundle` in this directory. The dev server creates a simp
``` text
webpack-dev-server --colors
-http://localhost:8080/index.html
+http://localhost:8080/webpack-dev-server/index.html
```
The app should display "It's working" with a green background.
@@ -21,8 +21,8 @@ There is a file named `index.html` in this directory. This file is served as con
``` text
webpack-dev-server --colors --config alternative.config.js
-http://localhost:8080/bundle
-http://localhost:8080/index.html
+http://localhost:8080/webpack-dev-server/bundle
+http://localhost:8080/webpack-dev-server/index.html
```
The app should be minimized and the image is included with a Data Url.
View
@@ -44,6 +44,10 @@ function Server(compiler, options) {
liveJs.pipe(res);
});
+ app.get("/webpack-dev-server/*", function(req, res) {
+ this.livePage.pipe(res);
+ }.bind(this));
+
// route content request
app.get("*", this.serveContent.bind(this));
}
@@ -64,36 +68,31 @@ Server.prototype.listen = function() {
Server.prototype.serveContent = function(req, res) {
var _path = req.path;
- if(/__webpack_dev_server$/.test(_path)) {
- _path = _path.replace(/__webpack_dev_server$/, "");
- if(_path === "/") _path = "";
- var target = this.contentBase + _path;
- if(/^(https?:)?\/\//.test(target)) {
- res.writeHead(302, {
- 'Location': target + (req._parsedUrl.search || "")
- });
- res.end();
- } else {
- fs.stat(target, function(err, stat) {
- if(!err && stat.isFile()) {
- fs.createReadStream(target).pipe(res);
- } else if(!err && stat.isDirectory()) {
- res.writeHead(302, {
- 'Location': req.path.replace(/__webpack_dev_server$/, (/\/$/.test(_path) || !_path ? "index.html__webpack_dev_server" : "/__webpack_dev_server")) + (req._parsedUrl.search || "")
- });
- res.end();
- } else {
- // Serve a page that executes the javascript
- res.write('<!DOCTYPE html><html><head><meta charset="utf-8"/></head><body><script type="text/javascript" charset="utf-8" src="');
- res.write(_path);
- res.write('.js');
- res.write(req._parsedUrl.search || "");
- res.end('"></script></body></html>');
- }
- }.bind(this));
- }
+ if(_path === "/") _path = "";
+ var target = this.contentBase + _path;
+ if(/^(https?:)?\/\//.test(target)) {
+ res.writeHead(302, {
+ 'Location': target + (req._parsedUrl.search || "")
+ });
+ res.end();
} else {
- this.livePage.pipe(res);
+ fs.stat(target, function(err, stat) {
+ if(!err && stat.isFile()) {
+ fs.createReadStream(target).pipe(res);
+ } else if(!err && stat.isDirectory()) {
+ res.writeHead(302, {
+ 'Location': req.path + (/\/$/.test(_path) || !_path ? "index.html" : "/") + (req._parsedUrl.search || "")
+ });
+ res.end();
+ } else {
+ // Serve a page that executes the javascript
+ res.write('<!DOCTYPE html><html><head><meta charset="utf-8"/></head><body><script type="text/javascript" charset="utf-8" src="');
+ res.write(_path);
+ res.write('.js');
+ res.write(req._parsedUrl.search || "");
+ res.end('"></script></body></html>');
+ }
+ }.bind(this));
}
}
View
@@ -1,6 +1,6 @@
{
"name": "webpack-dev-server",
- "version": "1.1.0",
+ "version": "1.2.0",
"author": "Tobias Koppers @sokra",
"description": "Serves a webpack app. Updates the browser on changes.",
"peerDependencies": {

0 comments on commit ef8f12a

Please sign in to comment.