-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathroutes.js
58 lines (49 loc) · 1.65 KB
/
routes.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
var express = require('express');
var path = require('path');
var getEnvironments = require('./api/getEnvironments.js');
var getDir = require('./api/getDir.js');
var startTest = require('./api/startTest');
var config = require('./config.js');
module.exports = function (app) {
app.use('/', express.static(path.join(__dirname, 'public')));
app.get('/environments', function (req, res) {
getEnvironments(config.nigthwatchConfigJsFolder, function (err, data) {
if (err) {
console.log('Error:', err);
return;
}
res.send(data);
});
});
app.get('/features', function (req, res) {
getDir(path.join(config.featuresParentFolder, config.featuresFolderName), function (err, data) {
if (err) {
console.log('Error:', err);
return;
}
res.send(data);
});
});
app.post('/launchspy', function (req, res) {
startTest(req.body, function (err, data) {
if (err) {
res.status(500).send(err);
} else {
res.status(200).send(data);
}
});
});
function getCommandLine() {
switch (process.platform) {
case 'darwin' : return 'open';
case 'win32' : return 'start';
case 'win64' : return 'start';
default : return 'xdg-open';
}
}
app.post('/open-file-in-editor', function (req, res) {
const exec = require('child_process').exec;
exec(getCommandLine() + ' ' + req.body.path);
res.status(200).send();
});
};