-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1712 from mixonic/tests-without-auto-or-history
Move /tests handler into its own middleware
- Loading branch information
Showing
8 changed files
with
92 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
|
||
var cleanBaseURL = require('../../../../utilities/clean-base-url'); | ||
|
||
function TestsServerAddon(project) { | ||
this.project = project; | ||
this.name = 'tests-server-middleware'; | ||
} | ||
|
||
TestsServerAddon.prototype.serverMiddleware = function(config) { | ||
var app = config.app; | ||
var options = config.options; | ||
var watcher = options.watcher; | ||
|
||
var baseURL = cleanBaseURL(options.baseURL); | ||
var testsRegexp = new RegExp('^' + baseURL + 'tests'); | ||
var baseURLRegexp = new RegExp('^' + baseURL); | ||
|
||
app.use(function(req, res, next) { | ||
watcher.then(function() { | ||
|
||
var acceptHeaders = req.headers.accept || []; | ||
var hasHTMLHeader = acceptHeaders.indexOf('text/html') !== -1; | ||
var hasWildcardHeader = acceptHeaders.indexOf('*/*') !== -1; | ||
|
||
var isForTests = testsRegexp.test(req.path); | ||
|
||
if (isForTests && (hasHTMLHeader || hasWildcardHeader) && req.method === 'GET') { | ||
if (baseURLRegexp.test(req.path)) { | ||
req.url = baseURL + 'tests/index.html'; | ||
} else { | ||
req.url = '/tests/index.html'; | ||
} | ||
} | ||
|
||
next(); | ||
}); | ||
}); | ||
}; | ||
|
||
module.exports = TestsServerAddon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "tests-server-middleware", | ||
"keywords": [ | ||
"ember-addon" | ||
], | ||
"ember-addon": { | ||
"before": "history-support-middleware" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters