-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
62 lines (51 loc) · 1.63 KB
/
index.js
File metadata and controls
62 lines (51 loc) · 1.63 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
import http from 'http';
import { server as WebSocketServer } from 'websocket';
import { remote } from 'webdriverio';
import dotenv from 'dotenv';
dotenv.config(); // .env 로드
const url = process.env.URL;
const webSocketsServerPort = process.env.PORT || 8080;
let browser;
// --- 브라우저 시작 ---
(async () => {
/* browser = await remote({
logLevel: 'info',
protocol: 'http',
hostname: 'localhost',
port: 9515,
path: '/',
capabilities: {
browserName: 'chrome'
}
}); */
browser = await remote({
logLevel: 'info',
capabilities: {
browserName: 'chrome',
},
});
await browser.url(url);
await browser.maximizeWindow();
const loginId = await browser.$('#login_id');
await loginId.setValue(process.env.LOGIN_ID);
const loginPwd = await browser.$('#login_password');
await loginPwd.setValue(process.env.LOGIN_PASSWORD);
const loginBtn = await browser.$('.btn_login');
await loginBtn.click();
})();
// --- WebSocket 서버 설정 ---
const server = http.createServer(() => {});
server.listen(webSocketsServerPort, "0.0.0.0", () => {
console.log(`Server is listening on port ${webSocketsServerPort}`);
});
const socket = new WebSocketServer({
httpServer: server,
autoAcceptConnections: false
});
// --- WebSocket 메시지 처리 ---
socket.on('request', (request) => {
const connection = request.accept(null, request.origin);
connection.on('message', async (message) => {
await browser.url(url + '/home/?search_type=field&search_field=phone&show_count=true&search_word='+message.utf8Data);
});
});