forked from CodecrumbsIO/codecrumbs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
58 lines (54 loc) · 1.58 KB
/
Copy pathindex.js
File metadata and controls
58 lines (54 loc) · 1.58 KB
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
const portscanner = require('portscanner');
const httpServer = require('http-server');
const { SERVER_PORT } = require('../shared/constants');
const mediator = require('./mediator');
const sourceWatcher = require('./source-watcher');
const setup = (
{ projectNameAlias, projectDir, entryPoint, webpackConfigPath, clientPort },
isDev
) => {
const PORT_IN_USE = 'open';
const HOST = '127.0.0.1';
Promise.all([
portscanner.checkPortStatus(clientPort, HOST).then(status => {
if (status !== PORT_IN_USE) {
/**
* socket+http server for data exchange between browser and source servers
*/
mediator.run({ port: SERVER_PORT, clientPort });
}
}),
portscanner.checkPortStatus(clientPort, HOST).then(status => {
if (status !== PORT_IN_USE) {
/**
* http server to host "codecrumbs" client source for browser
*/
httpServer
.createServer({ root: './src/public/dist/local', cache: isDev ? -1 : 3600 })
.listen(clientPort, HOST, () => {
console.log(`"Codecrumbs" client is served on http://localhost:${clientPort}`);
});
}
})
]).then(() => {
/**
* source server instance (one per source code project)
*/
sourceWatcher.run(
{
mediatorEndPoint: `${HOST}:${SERVER_PORT}`,
namespace: `source-project-${Date.now()}`,
projectName: `project-${projectNameAlias || projectDir}`
},
{
projectDir,
entryPoint,
webpackConfigPath,
clientPort
}
);
});
};
module.exports = {
setup
};