fix: resolve login network error behind Traefik proxy
This commit is contained in:
4
app.py
4
app.py
@@ -16,11 +16,9 @@ def create_app():
|
|||||||
app.secret_key = SECRET_KEY
|
app.secret_key = SECRET_KEY
|
||||||
app.config['SESSION_COOKIE_HTTPONLY'] = True
|
app.config['SESSION_COOKIE_HTTPONLY'] = True
|
||||||
app.config['SESSION_COOKIE_SAMESITE'] = 'Lax'
|
app.config['SESSION_COOKIE_SAMESITE'] = 'Lax'
|
||||||
app.config['SESSION_COOKIE_SECURE'] = os.getenv('FLASK_ENV') == 'production'
|
|
||||||
app.config['PERMANENT_SESSION_LIFETIME'] = 86400 # 24 hours
|
app.config['PERMANENT_SESSION_LIFETIME'] = 86400 # 24 hours
|
||||||
app.config['PREFERRED_URL_SCHEME'] = 'https'
|
|
||||||
|
|
||||||
# Trust the reverse proxy headers from Coolify/Traefik
|
# Behind Coolify/Traefik: trust proxy headers
|
||||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||||
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1)
|
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1)
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ services:
|
|||||||
- SECRET_KEY=${SECRET_KEY:-}
|
- SECRET_KEY=${SECRET_KEY:-}
|
||||||
- TTS_API_URL=${TTS_API_URL:-http://localhost:5010/api/v1}
|
- TTS_API_URL=${TTS_API_URL:-http://localhost:5010/api/v1}
|
||||||
- TTS_API_KEY=${TTS_API_KEY:-}
|
- TTS_API_KEY=${TTS_API_KEY:-}
|
||||||
- FLASK_ENV=production
|
|
||||||
volumes:
|
volumes:
|
||||||
- type: bind
|
- type: bind
|
||||||
source: /opt/apps/Audiobook Maker Pro-v4
|
source: /opt/apps/Audiobook Maker Pro-v4
|
||||||
|
|||||||
@@ -260,7 +260,7 @@
|
|||||||
|
|
||||||
<div class="login-footer">
|
<div class="login-footer">
|
||||||
<i class="bi bi-shield-lock me-1"></i>
|
<i class="bi bi-shield-lock me-1"></i>
|
||||||
Audiobook Maker Pro v3.1
|
Audiobook Maker Pro v4
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -295,18 +295,33 @@
|
|||||||
// Hide previous error
|
// Hide previous error
|
||||||
errorDiv.classList.remove('visible');
|
errorDiv.classList.remove('visible');
|
||||||
|
|
||||||
|
// Client-side validation
|
||||||
|
if (!username || !password) {
|
||||||
|
errorText.textContent = 'Please enter username and password.';
|
||||||
|
errorDiv.classList.add('visible');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Show loading
|
// Show loading
|
||||||
loginBtn.disabled = true;
|
loginBtn.disabled = true;
|
||||||
btnText.textContent = 'Signing in...';
|
btnText.textContent = 'Signing in...';
|
||||||
spinner.style.display = 'inline-block';
|
spinner.style.display = 'inline-block';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/auth/login', {
|
const response = await fetch(window.location.origin + '/api/auth/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 }),
|
||||||
|
redirect: 'follow',
|
||||||
|
credentials: 'same-origin'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Handle non-JSON responses (e.g., 500 server error pages)
|
||||||
|
const contentType = response.headers.get('content-type') || '';
|
||||||
|
if (!contentType.includes('application/json')) {
|
||||||
|
throw new Error('Server returned status ' + response.status);
|
||||||
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
if (data.error) {
|
if (data.error) {
|
||||||
@@ -326,7 +341,8 @@
|
|||||||
window.location.href = '/';
|
window.location.href = '/';
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
errorText.textContent = 'Network error. Please try again.';
|
console.error('Login fetch error:', error);
|
||||||
|
errorText.textContent = 'Connection error. Please try again.';
|
||||||
errorDiv.classList.add('visible');
|
errorDiv.classList.add('visible');
|
||||||
loginBtn.disabled = false;
|
loginBtn.disabled = false;
|
||||||
btnText.textContent = 'Sign In';
|
btnText.textContent = 'Sign In';
|
||||||
|
|||||||
Reference in New Issue
Block a user