forked from juju/juju-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-server.js
executable file
·49 lines (39 loc) · 1.7 KB
/
test-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
/*
This file is part of the Juju GUI, which lets users view and manage Juju
environments within a graphical interface (https://launchpad.net/juju-gui).
Copyright (C) 2012-2013 Canonical Ltd.
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU Affero General Public License version 3, as published by
the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
General Public License for more details.
You should have received a copy of the GNU Affero General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
*/
'use strict';
// process.argv[2] will be 'debug' or 'prod'
var express = require('express'),
http = require('http'),
fs = require('fs'),
path = require('path');
var app = express();
app.use(express.logger('dev'));
// 'static' is a reserved word so dot notation is not used to
// avoid annoying the linter.
app.use(express['static'](__dirname));
// fallback to looking in assets
app.use('/juju-ui', express['static'](
__dirname + '/build-' + process.argv[2] + '/juju-ui'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.get('/juju-ui/:file', function(req, res) {
var fileName = req.params.file;
res.sendfile('build-' + process.argv[2] + '/juju-ui/' + fileName);
});
var server = http.createServer(app);
// When run via the test-server.sh the PORT is set via an ENV variable.
var port = process.env.TEST_PORT || 8888;
server.listen(port);
console.log('http://0.0.0.0:' + port + '/test/index.html');