Arkm20 commited on
Commit
4a84245
·
verified ·
1 Parent(s): a2b768a

Create index.js

Browse files
Files changed (1) hide show
  1. index.js +39 -0
index.js ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import schedule from "node-schedule";
2
+ import { chromium } from "playwright";
3
+
4
+ const SUBDOMAIN = process.env.FALIX_SUBDOMAIN;
5
+ const START_URL = "https://falixnodes.net/startserver";
6
+
7
+ async function keepAlive() {
8
+ const browser = await chromium.launch({ headless: true });
9
+ const page = await browser.newPage();
10
+ await page.goto(START_URL, { waitUntil: "networkidle" });
11
+
12
+ // 1. Fill in the "Server Subdomain Name" field
13
+ await page.fill('input[type="text"]', SUBDOMAIN);
14
+
15
+ // 2. Wait for the Turnstile widget, grab its sitekey
16
+ const siteKey = await page.getAttribute("div.cf-turnstile", "data-sitekey");
17
+
18
+ // 3. Execute Turnstile in-page to get a token
19
+ const token = await page.evaluate((key) => {
20
+ return new Promise((resolve) => {
21
+ window.turnstile.render(document.querySelector("div.cf-turnstile"), {
22
+ sitekey: key,
23
+ callback: resolve
24
+ });
25
+ });
26
+ }, siteKey);
27
+
28
+ // 4. Inject the token and click “Start Server”
29
+ await page.fill('input[name="cf-turnstile-response"]', token);
30
+ await page.click('button[type="submit"]');
31
+
32
+ await browser.close();
33
+ console.log(new Date(), "✅ Start request sent");
34
+ }
35
+
36
+ // Schedule every 55 minutes to stay ahead of the ~1 hr free-tier shutdown :contentReference[oaicite:0]{index=0}
37
+ schedule.scheduleJob("*/55 * * * *", keepAlive);
38
+ // Run immediately on container start
39
+ keepAlive();