Fix Tailwind CSS styling configuration
- Add tailwind.config.ts with proper content paths and theme config - Add postcss.config.js for Tailwind and autoprefixer processing - Downgrade tailwindcss to v3.4.17 and add missing PostCSS dependencies - Update Dockerfile to clarify build process - Fix UI styling issues in Docker environment
This commit is contained in:
124
app/api/session-status/route.ts
Normal file
124
app/api/session-status/route.ts
Normal file
@@ -0,0 +1,124 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { tradingViewAutomation } from '../../../lib/tradingview-automation'
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
console.log('📊 Getting TradingView session status...')
|
||||
|
||||
// Initialize if not already done (Docker-safe initialization)
|
||||
if (!tradingViewAutomation['browser']) {
|
||||
console.log('🐳 Initializing TradingView automation in Docker environment...')
|
||||
await tradingViewAutomation.init()
|
||||
}
|
||||
|
||||
// Get lightweight session information without navigation
|
||||
const sessionInfo = await tradingViewAutomation.getQuickSessionStatus()
|
||||
|
||||
// Determine connection status based on browser state and URL
|
||||
let connectionStatus = 'unknown'
|
||||
if (sessionInfo.browserActive) {
|
||||
if (sessionInfo.currentUrl.includes('tradingview.com')) {
|
||||
connectionStatus = 'connected'
|
||||
} else if (sessionInfo.currentUrl) {
|
||||
connectionStatus = 'disconnected'
|
||||
} else {
|
||||
connectionStatus = 'unknown'
|
||||
}
|
||||
} else {
|
||||
connectionStatus = 'disconnected'
|
||||
}
|
||||
|
||||
const response = {
|
||||
success: true,
|
||||
session: {
|
||||
...sessionInfo,
|
||||
connectionStatus,
|
||||
lastChecked: new Date().toISOString(),
|
||||
dockerEnv: process.env.DOCKER_ENV === 'true',
|
||||
environment: process.env.NODE_ENV || 'development'
|
||||
}
|
||||
}
|
||||
|
||||
console.log('✅ Session status retrieved:', response.session)
|
||||
return NextResponse.json(response)
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Failed to get session status:', error)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Failed to get session status',
|
||||
session: {
|
||||
isAuthenticated: false,
|
||||
hasSavedCookies: false,
|
||||
hasSavedStorage: false,
|
||||
cookiesCount: 0,
|
||||
currentUrl: '',
|
||||
connectionStatus: 'error',
|
||||
lastChecked: new Date().toISOString(),
|
||||
dockerEnv: process.env.DOCKER_ENV === 'true',
|
||||
environment: process.env.NODE_ENV || 'development'
|
||||
}
|
||||
}, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const { action } = await request.json()
|
||||
console.log(`🔧 Session action requested: ${action} (Docker: ${process.env.DOCKER_ENV === 'true'})`)
|
||||
|
||||
// Initialize if not already done (Docker-safe initialization)
|
||||
if (!tradingViewAutomation['browser']) {
|
||||
console.log('🐳 Initializing TradingView automation for session action in Docker...')
|
||||
await tradingViewAutomation.init()
|
||||
}
|
||||
|
||||
let result: any = { success: true }
|
||||
|
||||
switch (action) {
|
||||
case 'refresh':
|
||||
const refreshed = await tradingViewAutomation.refreshSession()
|
||||
result.refreshed = refreshed
|
||||
result.message = refreshed ? 'Session refreshed successfully' : 'Failed to refresh session'
|
||||
break
|
||||
|
||||
case 'clear':
|
||||
await tradingViewAutomation.clearSession()
|
||||
result.message = 'Session data cleared successfully'
|
||||
break
|
||||
|
||||
case 'test':
|
||||
const testResult = await tradingViewAutomation.testSessionPersistence()
|
||||
result.testResult = testResult
|
||||
result.message = testResult.isValid ? 'Session is valid' : 'Session is invalid or expired'
|
||||
break
|
||||
|
||||
case 'login-status':
|
||||
const isLoggedIn = await tradingViewAutomation.checkLoginStatus()
|
||||
result.isLoggedIn = isLoggedIn
|
||||
result.message = isLoggedIn ? 'User is logged in' : 'User is not logged in'
|
||||
break
|
||||
|
||||
default:
|
||||
result.success = false
|
||||
result.error = `Unknown action: ${action}`
|
||||
return NextResponse.json(result, { status: 400 })
|
||||
}
|
||||
|
||||
console.log(`✅ Session action '${action}' completed:`, result)
|
||||
return NextResponse.json({
|
||||
...result,
|
||||
dockerEnv: process.env.DOCKER_ENV === 'true',
|
||||
environment: process.env.NODE_ENV || 'development'
|
||||
})
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Session action failed:', error)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Session action failed',
|
||||
dockerEnv: process.env.DOCKER_ENV === 'true',
|
||||
environment: process.env.NODE_ENV || 'development'
|
||||
}, { status: 500 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user