live-server-maintained 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +16 -0
- package/.github/CONTRIBUTING.md +19 -0
- package/.github/ISSUE_TEMPLATE.md +11 -0
- package/.travis.yml +5 -0
- package/README.md +12 -2
- package/index.js +403 -0
- package/injected.html +31 -0
- package/live-server.js +174 -0
- package/middleware/example.js +5 -0
- package/middleware/spa-ignore-assets.js +14 -0
- package/middleware/spa.js +13 -0
- package/package.json +68 -4
- package/test/acceptance.js +67 -0
- package/test/cli.js +65 -0
- package/test/conf/https.conf.js +7 -0
- package/test/conf/server.cert +21 -0
- package/test/conf/server.key +30 -0
- package/test/cors.js +42 -0
- package/test/data/fragment.html +3 -0
- package/test/data/htpasswd-test +1 -0
- package/test/data/index-caps.htm +13 -0
- package/test/data/index-head.html +8 -0
- package/test/data/index.html +12 -0
- package/test/data/middleware.js +5 -0
- package/test/data/style.css +1 -0
- package/test/data/sub/sub.html +10 -0
- package/test/data/test.svg +14 -0
- package/test/htpasswd.js +28 -0
- package/test/https.js +48 -0
- package/test/middleware.js +43 -0
- package/test/mount.js +30 -0
- package/test/proxy.js +28 -0
- package/test/spa.js +40 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Single Page Apps - redirect to /#/ except when a file extension is given
|
|
2
|
+
var path = require('path');
|
|
3
|
+
module.exports = function(req, res, next) {
|
|
4
|
+
if (req.method !== "GET" && req.method !== "HEAD")
|
|
5
|
+
next();
|
|
6
|
+
if (req.url !== '/' && path.extname(req.url) === '') {
|
|
7
|
+
var route = req.url;
|
|
8
|
+
req.url = '/';
|
|
9
|
+
res.statusCode = 302;
|
|
10
|
+
res.setHeader('Location', req.url + '#' + route);
|
|
11
|
+
res.end();
|
|
12
|
+
}
|
|
13
|
+
else next();
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Single Page Apps - redirect to /#/
|
|
2
|
+
module.exports = function(req, res, next) {
|
|
3
|
+
if (req.method !== "GET" && req.method !== "HEAD")
|
|
4
|
+
next();
|
|
5
|
+
if (req.url !== '/') {
|
|
6
|
+
var route = req.url;
|
|
7
|
+
req.url = '/';
|
|
8
|
+
res.statusCode = 302;
|
|
9
|
+
res.setHeader('Location', req.url + '#' + route);
|
|
10
|
+
res.end();
|
|
11
|
+
}
|
|
12
|
+
else next();
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "live-server-maintained",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "simple development http server with live reload capability",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"front-end",
|
|
7
|
+
"development",
|
|
8
|
+
"tool",
|
|
9
|
+
"server",
|
|
10
|
+
"http",
|
|
11
|
+
"cli"
|
|
12
|
+
],
|
|
13
|
+
"author": "Tapio Vierros",
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"chokidar": "^3.6.0",
|
|
16
|
+
"colors": "1.4.0",
|
|
17
|
+
"connect": "^3.7.0",
|
|
18
|
+
"cors": "^2.8.5",
|
|
19
|
+
"event-stream": "3.3.4",
|
|
20
|
+
"faye-websocket": "0.11.x",
|
|
21
|
+
"http-auth": "^4.2.1",
|
|
22
|
+
"morgan": "^1.10.0",
|
|
23
|
+
"object-assign": "^4.1.1",
|
|
24
|
+
"opn": "^5.5.0",
|
|
25
|
+
"proxy-middleware": "^0.15.0",
|
|
26
|
+
"send": "^0.19.0",
|
|
27
|
+
"serve-index": "^1.9.1"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"eslint": "^8.57.1",
|
|
31
|
+
"mocha": "^12.0.3",
|
|
32
|
+
"supertest": "^7.1.1"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"lint": "eslint live-server.js index.js",
|
|
36
|
+
"test": "mocha test --exit && npm run lint"
|
|
37
|
+
},
|
|
38
|
+
"bin": {
|
|
39
|
+
"lvm": "./live-server.js"
|
|
40
|
+
},
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://github.com/grape-corp/live-server-maintained.git"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=8.10.0"
|
|
47
|
+
},
|
|
48
|
+
"overrides": {
|
|
49
|
+
"braces": "^3.0.3",
|
|
50
|
+
"debug": "^2.6.9",
|
|
51
|
+
"ms": "^2.1.3",
|
|
52
|
+
"uuid": "^11.1.1"
|
|
53
|
+
},
|
|
54
|
+
"preferGlobal": true,
|
|
55
|
+
"license": "MIT",
|
|
56
|
+
"eslintConfig": {
|
|
57
|
+
"env": {
|
|
58
|
+
"node": true
|
|
59
|
+
},
|
|
60
|
+
"rules": {
|
|
61
|
+
"quotes": 0,
|
|
62
|
+
"curly": 0,
|
|
63
|
+
"strict": 0,
|
|
64
|
+
"no-process-exit": 0,
|
|
65
|
+
"eqeqeq": 1,
|
|
66
|
+
"no-unused-vars": 1,
|
|
67
|
+
"no-shadow": 1
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
var request = require('supertest');
|
|
2
|
+
var path = require('path');
|
|
3
|
+
var liveServer = require('..').start({
|
|
4
|
+
root: path.join(__dirname, "data"),
|
|
5
|
+
port: 0,
|
|
6
|
+
open: false
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
describe('basic functional tests', function(){
|
|
10
|
+
it('should respond with index.html', function(done){
|
|
11
|
+
request(liveServer)
|
|
12
|
+
.get('/')
|
|
13
|
+
.expect('Content-Type', 'text/html; charset=UTF-8')
|
|
14
|
+
.expect(/hello world/i)
|
|
15
|
+
.expect(200, done);
|
|
16
|
+
});
|
|
17
|
+
it('should have injected script', function(done){
|
|
18
|
+
request(liveServer)
|
|
19
|
+
.get('/')
|
|
20
|
+
.expect('Content-Type', 'text/html; charset=UTF-8')
|
|
21
|
+
.expect(/<script [^]+?live reload enabled[^]+?<\/script>/i)
|
|
22
|
+
.expect(200, done);
|
|
23
|
+
});
|
|
24
|
+
it('should inject script when tags are in CAPS', function(done){
|
|
25
|
+
request(liveServer)
|
|
26
|
+
.get('/index-caps.htm')
|
|
27
|
+
.expect('Content-Type', 'text/html; charset=UTF-8')
|
|
28
|
+
.expect(/<script [^]+?live reload enabled[^]+?<\/script>/i)
|
|
29
|
+
.expect(200, done);
|
|
30
|
+
});
|
|
31
|
+
it('should inject to <head> when no <body>', function(done){
|
|
32
|
+
request(liveServer)
|
|
33
|
+
.get('/index-head.html')
|
|
34
|
+
.expect('Content-Type', 'text/html; charset=UTF-8')
|
|
35
|
+
.expect(/<script [^]+?live reload enabled[^]+?<\/script>/i)
|
|
36
|
+
.expect(200, done);
|
|
37
|
+
});
|
|
38
|
+
it('should inject also svg files', function(done){
|
|
39
|
+
request(liveServer)
|
|
40
|
+
.get('/test.svg')
|
|
41
|
+
.expect('Content-Type', 'image/svg+xml')
|
|
42
|
+
.expect(function(res) {
|
|
43
|
+
if (res.body.toString().indexOf("Live reload enabled") == -1)
|
|
44
|
+
throw new Error("injected code not found");
|
|
45
|
+
})
|
|
46
|
+
.expect(200, done);
|
|
47
|
+
});
|
|
48
|
+
it('should not inject html fragments', function(done){
|
|
49
|
+
request(liveServer)
|
|
50
|
+
.get('/fragment.html')
|
|
51
|
+
.expect('Content-Type', 'text/html; charset=UTF-8')
|
|
52
|
+
.expect(function(res) {
|
|
53
|
+
if (res.text.toString().indexOf("Live reload enabled") > -1)
|
|
54
|
+
throw new Error("injected code should not be found");
|
|
55
|
+
})
|
|
56
|
+
.expect(200, done);
|
|
57
|
+
});
|
|
58
|
+
xit('should have WebSocket connection', function(done){
|
|
59
|
+
done(); // todo
|
|
60
|
+
});
|
|
61
|
+
xit('should reload on page change', function(done){
|
|
62
|
+
done(); // todo
|
|
63
|
+
});
|
|
64
|
+
xit('should reload (without refreshing) on css change', function(done){
|
|
65
|
+
done(); // todo
|
|
66
|
+
});
|
|
67
|
+
});
|
package/test/cli.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
var path = require('path');
|
|
3
|
+
var exec = require('child_process').execFile;
|
|
4
|
+
var cmd = path.join(__dirname, "..", "live-server.js");
|
|
5
|
+
var opts = {
|
|
6
|
+
timeout: 2000,
|
|
7
|
+
maxBuffer: 1024
|
|
8
|
+
};
|
|
9
|
+
function exec_test(args, callback) {
|
|
10
|
+
if (process.platform === 'win32')
|
|
11
|
+
exec(process.execPath, [ cmd ].concat(args), opts, callback);
|
|
12
|
+
else
|
|
13
|
+
exec(cmd, args, opts, callback);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe('command line usage', function() {
|
|
17
|
+
it('--version', function(done) {
|
|
18
|
+
exec_test([ "--version" ], function(error, stdout, stdin) {
|
|
19
|
+
assert(!error, error);
|
|
20
|
+
assert(stdout.indexOf("live-server") === 0, "version not found");
|
|
21
|
+
done();
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
it('--help', function(done) {
|
|
25
|
+
exec_test([ "--help" ], function(error, stdout, stdin) {
|
|
26
|
+
assert(!error, error);
|
|
27
|
+
assert(stdout.indexOf("Usage: live-server") === 0, "usage not found");
|
|
28
|
+
done();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
it('--quiet', function(done) {
|
|
32
|
+
exec_test([ "--quiet", "--no-browser", "--test" ], function(error, stdout, stdin) {
|
|
33
|
+
assert(!error, error);
|
|
34
|
+
assert(stdout === "", "stdout not empty");
|
|
35
|
+
done();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
it('--port', function(done) {
|
|
39
|
+
exec_test([ "--port=16123", "--no-browser", "--test" ], function(error, stdout, stdin) {
|
|
40
|
+
assert(!error, error);
|
|
41
|
+
assert(stdout.indexOf("Serving") >= 0, "serving string not found");
|
|
42
|
+
assert(stdout.indexOf("at http://127.0.0.1:16123") != -1, "port string not found");
|
|
43
|
+
done();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
it('--host', function(done) {
|
|
47
|
+
exec_test([ "--host=localhost", "--no-browser", "--test" ], function(error, stdout, stdin) {
|
|
48
|
+
assert(!error, error);
|
|
49
|
+
assert(stdout.indexOf("Serving") >= 0, "serving string not found");
|
|
50
|
+
assert(stdout.indexOf("at http://localhost:") != -1, "host string not found");
|
|
51
|
+
done();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
it('--htpasswd', function(done) {
|
|
55
|
+
exec_test(
|
|
56
|
+
[ "--htpasswd=" + path.join(__dirname, "data/htpasswd-test"),
|
|
57
|
+
"--no-browser",
|
|
58
|
+
"--test"
|
|
59
|
+
], function(error, stdout, stdin) {
|
|
60
|
+
assert(!error, error);
|
|
61
|
+
assert(stdout.indexOf("Serving") >= 0, "serving string not found");
|
|
62
|
+
done();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
|
2
|
+
MIIDbzCCAlegAwIBAgIJAITs++EKEa1pMA0GCSqGSIb3DQEBCwUAME4xCzAJBgNV
|
|
3
|
+
BAYTAlVTMQ0wCwYDVQQIDAR0ZXN0MQ0wCwYDVQQHDAR0ZXN0MSEwHwYDVQQKDBhJ
|
|
4
|
+
bnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwHhcNMTYwNDIzMDgwMDM0WhcNMTYwNTIz
|
|
5
|
+
MDgwMDM0WjBOMQswCQYDVQQGEwJVUzENMAsGA1UECAwEdGVzdDENMAsGA1UEBwwE
|
|
6
|
+
dGVzdDEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkq
|
|
7
|
+
hkiG9w0BAQEFAAOCAQ8AMIIBC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
|
+
var request = require('supertest');
|
|
2
|
+
var path = require('path');
|
|
3
|
+
var liveServer = require('..').start({
|
|
4
|
+
root: path.join(__dirname, "data"),
|
|
5
|
+
port: 0,
|
|
6
|
+
open: false,
|
|
7
|
+
cors: true
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
describe('cors tests', function() {
|
|
11
|
+
it('should respond with appropriate header', function(done) {
|
|
12
|
+
request(liveServer)
|
|
13
|
+
.get('/index.html')
|
|
14
|
+
.set('Origin', 'http://example.com')
|
|
15
|
+
.expect('Content-Type', 'text/html; charset=UTF-8')
|
|
16
|
+
.expect('Access-Control-Allow-Origin', 'http://example.com')
|
|
17
|
+
.expect(/Hello world/i)
|
|
18
|
+
.expect(200, done);
|
|
19
|
+
});
|
|
20
|
+
it('should support preflighted requests', function(done) {
|
|
21
|
+
request(liveServer)
|
|
22
|
+
.options('/index.html')
|
|
23
|
+
.set('Origin', 'http://example.com')
|
|
24
|
+
.set('Access-Control-Request-Method', 'POST')
|
|
25
|
+
.set('Access-Control-Request-Headers', 'X-PINGOTHER')
|
|
26
|
+
.expect('Access-Control-Allow-Origin', 'http://example.com')
|
|
27
|
+
.expect('Access-Control-Allow-Methods', /POST/)
|
|
28
|
+
.expect('Access-Control-Allow-Headers', 'X-PINGOTHER')
|
|
29
|
+
.expect(204, done);
|
|
30
|
+
});
|
|
31
|
+
it('should support requests with credentials', function(done) {
|
|
32
|
+
request(liveServer)
|
|
33
|
+
.options('/index.html')
|
|
34
|
+
.set('Origin', 'http://example.com')
|
|
35
|
+
.set('Cookie', 'foo=bar')
|
|
36
|
+
.expect('Access-Control-Allow-Origin', 'http://example.com')
|
|
37
|
+
.expect('Access-Control-Allow-Credentials', 'true')
|
|
38
|
+
.expect(204, done);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
test:$apr1$edJu7/51$LVD5BTHDtDMzzeeYnWXCL1
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
|
2
|
+
"http://www.w3.org/TR/html4/strict.dtd">
|
|
3
|
+
<HTML lang="en">
|
|
4
|
+
<HEAD>
|
|
5
|
+
<META http-equiv="Content-Type" content="text/html; charset=utf-8" >
|
|
6
|
+
<TITLE>Live-server Test Page</TITLE>
|
|
7
|
+
<LINK rel="stylesheet" href="style.css" >
|
|
8
|
+
</HEAD>
|
|
9
|
+
<BODY>
|
|
10
|
+
<H1>Hello world.</H1>
|
|
11
|
+
<P>These tags are in capitals.</P>
|
|
12
|
+
</BODY>
|
|
13
|
+
</HTML>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<title>Live-server Test Page</title>
|
|
6
|
+
<link rel="stylesheet" href="style.css" />
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<h1>Hello world.</h1>
|
|
10
|
+
<p>Edit my css for a live-reload without refreshing.</p>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
h1 { color: red; }
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<svg width="100%" height="100%" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
// <![CDATA[
|
|
4
|
+
function change(evt) {
|
|
5
|
+
var target = evt.target;
|
|
6
|
+
var radius = target.getAttribute("r");
|
|
7
|
+
radius = (radius == 15) ? 45 : 15
|
|
8
|
+
target.setAttribute("r", radius);
|
|
9
|
+
}
|
|
10
|
+
// ]]>
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<circle cx="50" cy="50" r="45" fill="green" onclick="change(evt)" />
|
|
14
|
+
</svg>
|
package/test/htpasswd.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var request = require('supertest');
|
|
2
|
+
var path = require('path');
|
|
3
|
+
var liveServer = require('..').start({
|
|
4
|
+
root: path.join(__dirname, "data"),
|
|
5
|
+
port: 0,
|
|
6
|
+
open: false,
|
|
7
|
+
htpasswd: path.join(__dirname, "data", "htpasswd-test")
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
describe('htpasswd tests', function() {
|
|
11
|
+
it('should respond with 401 since no password is given', function(done) {
|
|
12
|
+
request(liveServer)
|
|
13
|
+
.get('/')
|
|
14
|
+
.expect(401, done);
|
|
15
|
+
});
|
|
16
|
+
it('should respond with 401 since wrong password is given', function(done) {
|
|
17
|
+
request(liveServer)
|
|
18
|
+
.get('/')
|
|
19
|
+
.auth("test", "not-real-password")
|
|
20
|
+
.expect(401, done);
|
|
21
|
+
});
|
|
22
|
+
it('should respond with 200 since correct password is given', function(done) {
|
|
23
|
+
request(liveServer)
|
|
24
|
+
.get('/')
|
|
25
|
+
.auth("test", "test")
|
|
26
|
+
.expect(200, done);
|
|
27
|
+
});
|
|
28
|
+
});
|
package/test/https.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var request = require('supertest');
|
|
2
|
+
var path = require('path');
|
|
3
|
+
// accept self-signed certificates
|
|
4
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
|
5
|
+
|
|
6
|
+
function tests(liveServer) {
|
|
7
|
+
it('should reply with a correct index file', function(done) {
|
|
8
|
+
request(liveServer)
|
|
9
|
+
.get('/index.html')
|
|
10
|
+
.expect('Content-Type', 'text/html; charset=UTF-8')
|
|
11
|
+
.expect(/Hello world/i)
|
|
12
|
+
.expect(200, done);
|
|
13
|
+
});
|
|
14
|
+
it('should support head request', function(done) {
|
|
15
|
+
request(liveServer)
|
|
16
|
+
.head('/index.html')
|
|
17
|
+
.expect('Content-Type', 'text/html; charset=UTF-8')
|
|
18
|
+
.expect(200, done);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe('https tests with external module', function() {
|
|
23
|
+
var opts = {
|
|
24
|
+
root: path.join(__dirname, 'data'),
|
|
25
|
+
port: 0,
|
|
26
|
+
open: false,
|
|
27
|
+
https: path.join(__dirname, 'conf/https.conf.js')
|
|
28
|
+
};
|
|
29
|
+
var liveServer = require("..").start(opts);
|
|
30
|
+
tests(liveServer);
|
|
31
|
+
after(function () {
|
|
32
|
+
liveServer.close()
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('https tests with object', function() {
|
|
37
|
+
var opts = {
|
|
38
|
+
root: path.join(__dirname, 'data'),
|
|
39
|
+
port: 0,
|
|
40
|
+
open: false,
|
|
41
|
+
https: require(path.join(__dirname, 'conf/https.conf.js'))
|
|
42
|
+
};
|
|
43
|
+
var liveServer = require("..").start(opts);
|
|
44
|
+
tests(liveServer);
|
|
45
|
+
after(function () {
|
|
46
|
+
liveServer.close()
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
var request = require('supertest');
|
|
2
|
+
var path = require('path');
|
|
3
|
+
var liveServer1 = require('..').start({
|
|
4
|
+
root: path.join(__dirname, 'data'),
|
|
5
|
+
port: 0,
|
|
6
|
+
open: false,
|
|
7
|
+
middleware: [
|
|
8
|
+
function setStatus(req, res, next) {
|
|
9
|
+
res.statusCode = 201;
|
|
10
|
+
next();
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
});
|
|
14
|
+
var liveServer2 = require('..').start({
|
|
15
|
+
root: path.join(__dirname, 'data'),
|
|
16
|
+
port: 0,
|
|
17
|
+
open: false,
|
|
18
|
+
middleware: [ "example" ]
|
|
19
|
+
});
|
|
20
|
+
var liveServer3 = require('..').start({
|
|
21
|
+
root: path.join(__dirname, 'data'),
|
|
22
|
+
port: 0,
|
|
23
|
+
open: false,
|
|
24
|
+
middleware: [ path.join(__dirname, 'data', 'middleware.js') ]
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('middleware tests', function() {
|
|
28
|
+
it("should respond with middleware function's status code", function(done) {
|
|
29
|
+
request(liveServer1)
|
|
30
|
+
.get('/')
|
|
31
|
+
.expect(201, done);
|
|
32
|
+
});
|
|
33
|
+
it("should respond with built-in middleware's status code", function(done) {
|
|
34
|
+
request(liveServer2)
|
|
35
|
+
.get('/')
|
|
36
|
+
.expect(202, done);
|
|
37
|
+
});
|
|
38
|
+
it("should respond with external middleware's status code", function(done) {
|
|
39
|
+
request(liveServer3)
|
|
40
|
+
.get('/')
|
|
41
|
+
.expect(203, done);
|
|
42
|
+
});
|
|
43
|
+
});
|
package/test/mount.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var request = require('supertest');
|
|
2
|
+
var path = require('path');
|
|
3
|
+
var liveServer = require('..').start({
|
|
4
|
+
root: path.join(__dirname, "data"),
|
|
5
|
+
port: 0,
|
|
6
|
+
open: false,
|
|
7
|
+
mount: [
|
|
8
|
+
[ "/mounted", path.join(__dirname, "data", "sub") ],
|
|
9
|
+
[ "/style", path.join(__dirname, "data", "style.css") ]
|
|
10
|
+
]
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
describe('mount tests', function() {
|
|
14
|
+
it('should respond with sub.html', function(done) {
|
|
15
|
+
request(liveServer)
|
|
16
|
+
.get('/mounted/sub.html')
|
|
17
|
+
.expect('Content-Type', 'text/html; charset=UTF-8')
|
|
18
|
+
.expect(/Subdirectory/i)
|
|
19
|
+
.expect(200, done);
|
|
20
|
+
});
|
|
21
|
+
it('should respond with style.css', function(done) {
|
|
22
|
+
request(liveServer)
|
|
23
|
+
.get('/style')
|
|
24
|
+
.expect('Content-Type', 'text/css; charset=UTF-8')
|
|
25
|
+
.expect(/color/i)
|
|
26
|
+
.expect(200, done);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
|
package/test/proxy.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var request = require('supertest');
|
|
2
|
+
var path = require('path');
|
|
3
|
+
var port = 40200;
|
|
4
|
+
var server1 = require('..').start({
|
|
5
|
+
root: path.join(__dirname, "data"),
|
|
6
|
+
port: port,
|
|
7
|
+
open: false
|
|
8
|
+
});
|
|
9
|
+
var server2 = require('..').start({
|
|
10
|
+
root: path.join(__dirname, "data"),
|
|
11
|
+
port: 0,
|
|
12
|
+
open: false,
|
|
13
|
+
proxy: [
|
|
14
|
+
["/server1", "http://localhost:" + port]
|
|
15
|
+
]
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('proxy tests', function() {
|
|
19
|
+
it('should respond with proxied content', function(done) {
|
|
20
|
+
request(server2)
|
|
21
|
+
.get('/server1/index.html')
|
|
22
|
+
.expect('Content-Type', 'text/html; charset=UTF-8')
|
|
23
|
+
.expect(/Hello world/i)
|
|
24
|
+
.expect(200, done);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
|
package/test/spa.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var request = require('supertest');
|
|
2
|
+
var path = require('path');
|
|
3
|
+
var liveServerSpa = require('..').start({
|
|
4
|
+
root: path.join(__dirname, "data"),
|
|
5
|
+
port: 0,
|
|
6
|
+
open: false,
|
|
7
|
+
middleware: [ "spa" ]
|
|
8
|
+
});
|
|
9
|
+
var liveServerSpaIgnoreAssets = require('..').start({
|
|
10
|
+
root: path.join(__dirname, "data"),
|
|
11
|
+
port: 0,
|
|
12
|
+
open: false,
|
|
13
|
+
middleware: [ "spa-ignore-assets" ]
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe('spa tests', function(){
|
|
17
|
+
it('spa should redirect', function(done){
|
|
18
|
+
request(liveServerSpa)
|
|
19
|
+
.get('/api')
|
|
20
|
+
.expect('Location', /\/#\//)
|
|
21
|
+
.expect(302, done);
|
|
22
|
+
});
|
|
23
|
+
it('spa should redirect everything', function(done){
|
|
24
|
+
request(liveServerSpa)
|
|
25
|
+
.get('/style.css')
|
|
26
|
+
.expect('Location', /\/#\//)
|
|
27
|
+
.expect(302, done);
|
|
28
|
+
});
|
|
29
|
+
it('spa-ignore-assets should redirect something', function(done){
|
|
30
|
+
request(liveServerSpaIgnoreAssets)
|
|
31
|
+
.get('/api')
|
|
32
|
+
.expect('Location', /\/#\//)
|
|
33
|
+
.expect(302, done);
|
|
34
|
+
});
|
|
35
|
+
it('spa-ignore-assets should not redirect .css', function(done){
|
|
36
|
+
request(liveServerSpaIgnoreAssets)
|
|
37
|
+
.get('/style.css')
|
|
38
|
+
.expect(200, done);
|
|
39
|
+
});
|
|
40
|
+
});
|