-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathserver.js
78 lines (66 loc) · 2.42 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
Inject
Copyright 2011 LinkedIn
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS
IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
var fs = require('fs');
var path = require("path");
var util = require("util");
var express = require("express");
var exec = require('child_process').exec;
var app = express();
/**
* ========== Inject Integrated Test Server
*/
function delay(amount) {
return function(req, res, next) {
setTimeout(function() {
next();
}, amount);
};
}
// very special redirects...
app.get('/tests/doh/runner.js', function(req, res) {
return res.redirect('/tests/spec/amd/amdjs-tests/tests/doh/runner.js');
});
app.get('/tests/doh/_browserRunner.js', function(req, res) {
return res.redirect('/tests/spec/amd/amdjs-tests/tests/doh/_browserRunner.js');
});
app.get('/tests/spec/amd/amdjs-tests/impl/inject/inject.js', function(req, res) {
return res.redirect('/inject.js');
});
app.get('/tests/spec/amd/amdjs-tests/impl/inject/config.js', function(req, res) {
return res.redirect('/tests/spec/amd/amd-config.js');
});
// end "very special" section
app.use('/examples/dependencies/addrule/jqueryui/jquery.ui.widget.min.js', delay(3000));
app.use('/tests/spec/modules-1.1.1/includes/bugs/bug_56_a.js', delay(300));
app.use('/tests/spec/amd/includes/bugs/bug_56_a.js', delay(300));
app.get('/inject.js', function(req, res) {
return res.redirect('/dist/recent/inject.js');
});
app.get('/node_modules/*', function(req, res) {
fs.readFile(path.normalize('.' + req.path), function(err, data) {
// this hack exists because fiber doesn't check module.exports, just module
var out = [
'var oldM = module; var oldD = define;',
'var module = undefined; var define = undefined;',
data.toString(),
'module = oldM;',
'define = oldD;',
'oldM = oldD = undefined;'
];
res.end(out.join('\n'));
});
});
app.use(express.static(path.normalize(__dirname)));
app.use(express.static(path.normalize(path.join(__dirname, './', 'dist/recent'))));
module.exports = app;