fix: changes the API for localhost

main
Kirubakaran 2025-09-11 01:55:34 +05:30
parent 0c2d220918
commit 1054d3dc0b
8 changed files with 13 additions and 11 deletions

View File

@ -36,9 +36,11 @@ app = Flask(__name__)
# CORS(app, resources={r"/api/*": {"origins": "http://127.0.0.1:5500"}}, supports_credentials=True) # CORS(app, resources={r"/api/*": {"origins": "http://127.0.0.1:5500"}}, supports_credentials=True)
CORS(app, resources={r"/api/*": {"origins": "http://127.0.0.1:5500"}}, supports_credentials=True, expose_headers='Content-Disposition') # CORS(app, resources={r"/api/*": {"origins": "http://127.0.0.1:5500"}}, supports_credentials=True, expose_headers='Content-Disposition')
# CORS(app, resources={r"/api/*": {"origins": "http://localhost:5173"}}) CORS(app, resources={r"/api/*": {"origins": ["http://192.168.1.8:5500","http://127.0.0.1:5500"]}}, supports_credentials=True, expose_headers='Content-Disposition')
# CORS(app, resources={r"/api/*": {"origins": "http://localhost:5173"}}) , "http://127.0.0.1:5500"
# This tells Flask: "For any route starting with /api/, allow requests # This tells Flask: "For any route starting with /api/, allow requests
# from the frontend running on http://localhost:5173". # from the frontend running on http://localhost:5173".
@ -482,5 +484,5 @@ if __name__ == '__main__':
mqtt_thread = threading.Thread(target=start_mqtt_clients, daemon=True) mqtt_thread = threading.Thread(target=start_mqtt_clients, daemon=True)
mqtt_thread.start() mqtt_thread.start()
print(f"Starting Flask-SocketIO server on http://localhost:5000") print(f"Starting Flask-SocketIO server on http://192.168.1.8:5000")
socketio.run(app, host='0.0.0.0', port=5000) socketio.run(app, host='192.168.1.8', port=5000)

View File

@ -11,7 +11,7 @@ document.addEventListener('DOMContentLoaded', () => {
const password = document.getElementById('password').value; const password = document.getElementById('password').value;
try { try {
const response = await fetch('http://localhost:5000/api/login', { const response = await fetch('http://192.168.1.8:5000/api/login', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password }), body: JSON.stringify({ username, password }),

View File

@ -1,7 +1,7 @@
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
// --- CONFIGURATION --- // --- CONFIGURATION ---
const SOCKET_URL = "http://localhost:5000"; const SOCKET_URL = "http://192.168.1.8:5000";
const API_BASE = "http://localhost:5000/api"; // Added for API calls const API_BASE = "http://192.168.1.8:5000/api"; // Added for API calls
// --- DOM ELEMENT REFERENCES --- // --- DOM ELEMENT REFERENCES ---
const grid = document.getElementById('chambersGrid'); const grid = document.getElementById('chambersGrid');

View File

@ -1,7 +1,7 @@
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
// --- CONFIGURATION --- // --- CONFIGURATION ---
const SOCKET_URL = "http://localhost:5000"; const SOCKET_URL = "http://192.168.1.8:5000";
const API_BASE = "http://localhost:5000/api"; const API_BASE = "http://192.168.1.8:5000/api";
// --- DOM ELEMENT REFERENCES --- // --- DOM ELEMENT REFERENCES ---
const stationNameEl = document.getElementById('station-name'); const stationNameEl = document.getElementById('station-name');

View File

@ -86,7 +86,7 @@ document.addEventListener('DOMContentLoaded', () => {
// --- DATA FETCHING & STATUS POLLING --- // --- DATA FETCHING & STATUS POLLING ---
const loadAndPollStations = async () => { const loadAndPollStations = async () => {
try { try {
const response = await fetch('http://localhost:5000/api/stations'); const response = await fetch('http://192.168.1.8:5000/api/stations');
if (!response.ok) throw new Error('Failed to fetch stations'); if (!response.ok) throw new Error('Failed to fetch stations');
const stations = await response.json(); const stations = await response.json();

View File

@ -195,7 +195,7 @@
</div> </div>
<script> <script>
const API_BASE = 'http://localhost:5000/api'; const API_BASE = 'http://192.168.1.8:5000/api';
const grid = document.getElementById('stations-grid'); const grid = document.getElementById('stations-grid');
const addStationCardTmpl = document.getElementById('add-station-card-template'); const addStationCardTmpl = document.getElementById('add-station-card-template');