-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathindex.js
68 lines (54 loc) · 1.86 KB
/
index.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
/* eslint-env node */
"use strict";
// if using native backstop remote server
const BACKSTOP_REMOTE_HTTP_PORT = process.env.BACKSTOP_REMOTE_HTTP_PORT || 3000;
const BACKSTOP_PROXY_PATH = "/backstop";
const BACKSTOP_PROXY_TARGET = `http://localhost:${BACKSTOP_REMOTE_HTTP_PORT}`;
const BACKSTOP_ADDON_CONFIG_FILE_NAME = "ember-backstop.json";
module.exports = {
name: "ember-backstop",
isDevelopingAddon() {
return true;
},
serverMiddleware({ app }) {
this._configMiddleware(app);
},
testemMiddleware(app) {
this._configMiddleware(app);
},
includedCommands() {
return {
"backstop:remote": require("./commands/backstop-remote"),
"backstop:approve": require("./commands/backstop-approve"),
"backstop:report": require("./commands/backstop-report"),
"backstop:stop": require("./commands/backstop-stop"),
// 'backstop:test': require('./commands/backstop-test')
};
},
_configMiddleware(app) {
const config = getConfig(this.project);
// if using native backstop remote server
const proxy = require("http-proxy").createProxyServer({});
proxy.on("error", function (err, req, res) {
res.writeHead(config.skipRemoteError ? 503 : 500, {
"Content-Type": "text/plain",
});
res.end(err + " Please check that backstop-remote service is running.");
});
app.use(BACKSTOP_PROXY_PATH, function (req, res, next) {
proxy.web(req, res, { target: BACKSTOP_PROXY_TARGET });
});
},
};
function getConfig(project) {
let configDir = "config";
if (project.pkg["ember-addon"] && project.pkg["ember-addon"]["configPath"]) {
configDir = project.pkg["ember-addon"]["configPath"];
}
const config = {};
try {
const configPath = `./${configDir}/${BACKSTOP_ADDON_CONFIG_FILE_NAME}`;
Object.assign(config, project.require(configPath));
} catch (err) {}
return config;
}