-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
38 lines (34 loc) · 1.55 KB
/
Copy pathscript.js
File metadata and controls
38 lines (34 loc) · 1.55 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
/**
* api.js — FastAPI communication only.
* All visual/animation logic lives in index.html.
*/
document.getElementById('generate-btn').addEventListener('click', () => {
// 1. Grab current values from your HTML inputs
const length = document.getElementById('length-slider').value;
const includeDigits = document.getElementById('digits-checkbox').checked;
const includeSpecials = document.getElementById('specials-checkbox').checked;
// 2. Signal loading state to the UI layer
window.ui.setLoading(true);
// 3. Build the dynamic URL pointing to your local FastAPI server
// Automatically swaps between local testing and your live Render server
const base_url = window.location.hostname === "127.0.0.1" || window.location.hostname === "localhost"
? "http://127.0.0.1:8000"
: "https://fastapi-test-5nyx.onrender.com";
// Build the request using your live endpoint path
const url = `${base_url}/api/generate?length=${length}&use_digits=${includeDigits}&use_specials=${includeSpecials}`;
// 4. Send the request to Python
fetch(url)
.then(response => response.json())
.then(data => {
// 5. Hand the password string to the UI layer for display
window.ui.setPassword(data.password);
})
.catch(error => {
console.error("Error linking to backend:", error);
window.ui.setPassword("Server Error. Is Python running?");
})
.finally(() => {
// 6. Always restore the button
window.ui.setLoading(false);
});
});