Skip to content

Commit 4a01611

Browse files
committed
Remove redundant if statement in contentBase
1 parent 2639edc commit 4a01611

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

lib/Server.js

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -201,36 +201,34 @@ function Server(compiler, options) {
201201
},
202202

203203
contentBase: function() {
204-
if(options.contentBase !== false) {
205-
var contentBase = options.contentBase || process.cwd();
204+
var contentBase = options.contentBase || process.cwd();
206205

207-
if(Array.isArray(contentBase)) {
208-
contentBase.forEach(function(item) {
209-
app.get("*", express.static(item));
210-
});
211-
contentBase.forEach(function(item) {
212-
app.get("*", serveIndex(item));
213-
});
214-
} else if(/^(https?:)?\/\//.test(contentBase)) {
215-
// Redirect every request to contentBase
216-
app.get("*", function(req, res) {
217-
res.writeHead(302, {
218-
'Location': contentBase + req.path + (req._parsedUrl.search || "")
219-
});
220-
res.end();
206+
if(Array.isArray(contentBase)) {
207+
contentBase.forEach(function(item) {
208+
app.get("*", express.static(item));
209+
});
210+
contentBase.forEach(function(item) {
211+
app.get("*", serveIndex(item));
212+
});
213+
} else if(/^(https?:)?\/\//.test(contentBase)) {
214+
// Redirect every request to contentBase
215+
app.get("*", function(req, res) {
216+
res.writeHead(302, {
217+
'Location': contentBase + req.path + (req._parsedUrl.search || "")
221218
});
222-
} else if(typeof contentBase === "number") {
223-
// Redirect every request to the port contentBase
224-
app.get("*", function(req, res) {
225-
res.writeHead(302, {
226-
'Location': "//localhost:" + contentBase + req.path + (req._parsedUrl.search || "")
227-
});
228-
res.end();
219+
res.end();
220+
});
221+
} else if(typeof contentBase === "number") {
222+
// Redirect every request to the port contentBase
223+
app.get("*", function(req, res) {
224+
res.writeHead(302, {
225+
'Location': "//localhost:" + contentBase + req.path + (req._parsedUrl.search || "")
229226
});
230-
} else {
231-
// route content request
232-
app.get("*", express.static(contentBase, options.staticOptions), serveIndex(contentBase));
233-
}
227+
res.end();
228+
});
229+
} else {
230+
// route content request
231+
app.get("*", express.static(contentBase, options.staticOptions), serveIndex(contentBase));
234232
}
235233
},
236234

0 commit comments

Comments
 (0)