-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.js
More file actions
141 lines (119 loc) · 4.66 KB
/
start.js
File metadata and controls
141 lines (119 loc) · 4.66 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* Multi-Server Startup Script
*
* This script starts Site A, Site B, and Site C servers simultaneously
* without requiring any external dependencies.
*/
const { spawn } = require('child_process');
const { execSync } = require('child_process');
const path = require('path');
const dns = require('dns');
const servers = [
{
name: 'Site A',
script: path.join(__dirname, 'site-a', 'server.js'),
port: 3001,
hostname: 'site-a.local',
color: '\x1b[36m' // Cyan
},
{
name: 'Site B',
script: path.join(__dirname, 'site-b', 'server.js'),
port: 3002,
hostname: 'site-b.local',
color: '\x1b[35m' // Magenta
},
{
name: 'Site C',
script: path.join(__dirname, 'site-c', 'server.js'),
port: 3003,
hostname: 'site-c.local',
color: '\x1b[33m' // Yellow
}
];
const reset = '\x1b[0m';
const red = '\x1b[31m';
const green = '\x1b[32m';
const yellow = '\x1b[33m';
console.log('\n========================================');
console.log(' Adobe Analytics Cross-Domain Test');
console.log('========================================\n');
// Check hosts file configuration
function checkHostsConfig() {
return new Promise((resolve) => {
console.log('Checking hosts file configuration...\n');
let allConfigured = true;
let checkCount = 0;
servers.forEach(server => {
dns.lookup(server.hostname, (err, address) => {
checkCount++;
if (err || address !== '127.0.0.1') {
console.log(` ${red}✗${reset} ${server.hostname} - Not configured`);
allConfigured = false;
} else {
console.log(` ${green}✓${reset} ${server.hostname} -> ${address}`);
}
if (checkCount === servers.length) {
if (!allConfigured) {
console.log(`\n${yellow}WARNING: Some hostnames are not configured in /etc/hosts${reset}`);
console.log('\nPlease add the following lines to your /etc/hosts file:\n');
console.log(' 127.0.0.1 site-a.local');
console.log(' 127.0.0.1 site-b.local');
console.log(' 127.0.0.1 site-c.local');
console.log('\nOn macOS/Linux: sudo nano /etc/hosts');
console.log('On Windows: Edit C:\\Windows\\System32\\drivers\\etc\\hosts as Administrator');
console.log('\n' + yellow + 'Without this configuration, cross-domain tracking will not work correctly!' + reset);
console.log('(Cookie/localStorage will be shared across all sites on localhost)\n');
} else {
console.log(`\n${green}All hostnames are properly configured!${reset}\n`);
}
resolve(allConfigured);
}
});
});
});
}
// Start servers
async function startServers() {
const hostsConfigured = await checkHostsConfig();
const processes = [];
servers.forEach(server => {
const proc = spawn('node', [server.script], {
env: { ...process.env, PORT: server.port.toString() },
stdio: ['inherit', 'pipe', 'pipe']
});
processes.push(proc);
proc.stdout.on('data', (data) => {
console.log(`${server.color}[${server.name}]${reset} ${data.toString().trim()}`);
});
proc.stderr.on('data', (data) => {
console.error(`${server.color}[${server.name}]${reset} ${red}ERROR:${reset} ${data.toString().trim()}`);
});
proc.on('close', (code) => {
console.log(`${server.color}[${server.name}]${reset} Process exited with code ${code}`);
});
});
console.log('Starting servers...\n');
console.log('Access the test sites at:');
if (hostsConfigured) {
console.log(` ${servers[0].color}Site A:${reset} http://${servers[0].hostname}:${servers[0].port}/ (Cross-Domain Enabled)`);
console.log(` ${servers[1].color}Site B:${reset} http://${servers[1].hostname}:${servers[1].port}/ (Cross-Domain Enabled)`);
console.log(` ${servers[2].color}Site C:${reset} http://${servers[2].hostname}:${servers[2].port}/ (Cross-Domain DISABLED)`);
} else {
console.log(` ${servers[0].color}Site A:${reset} http://localhost:${servers[0].port}/ ${yellow}(hosts not configured)${reset}`);
console.log(` ${servers[1].color}Site B:${reset} http://localhost:${servers[1].port}/ ${yellow}(hosts not configured)${reset}`);
console.log(` ${servers[2].color}Site C:${reset} http://localhost:${servers[2].port}/ ${yellow}(hosts not configured)${reset}`);
}
console.log('\nPress Ctrl+C to stop all servers.\n');
// Handle graceful shutdown
process.on('SIGINT', () => {
console.log('\n\nShutting down servers...');
processes.forEach(proc => proc.kill());
process.exit(0);
});
process.on('SIGTERM', () => {
processes.forEach(proc => proc.kill());
process.exit(0);
});
}
startServers();