fix: update pass credentials to container

This commit is contained in:
2025-08-21 11:41:30 +02:00
parent 6c553bea8a
commit e96bcb7a94
4 changed files with 190 additions and 102 deletions

View File

@ -3,7 +3,7 @@
<div class="waiting-container">
<h2>Container Status: {{ status }}</h2>
<p v-if="status === 'ready'">
Your container is ready! <a :href="`http://${ip}`" target="_blank">Open it</a>
Your container is ready! <a :href="openLink" target="_blank" rel="noopener">Open it</a>
</p>
<p v-else-if="status === 'running'">Waiting for services to be ready...</p>
<p v-else-if="status === 'starting'">Starting container...</p>
@ -14,13 +14,25 @@
</template>
<script setup>
import { ref, onMounted, onUnmounted } from 'vue' // <— sicher importieren
import { ref, onMounted, onUnmounted, computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'
const route = useRoute()
const router = useRouter()
const name = route.query.name
const redirect = route.query.redirect
const name = String(route.query.name || '')
const handoff = typeof route.query.handoff === 'string' ? route.query.handoff : ''
const rawPath = typeof route.query.path === 'string' ? route.query.path : '/login'
function sanitizePath(p) {
if (typeof p !== 'string') return '/login'
if (p.startsWith('http://') || p.startsWith('https://')) return '/login'
if (!p.startsWith('/')) return '/login'
const allowed = new Set(['/', '/login', '/signin'])
const pathOnly = p.split('?')[0]
return allowed.has(pathOnly) ? p : '/login'
}
const safePath = sanitizePath(rawPath)
const loading = ref(true)
const status = ref('starting')
@ -28,41 +40,38 @@ const ip = ref(null)
const interval = ref(null)
const errorMessage = ref(null)
const POLL_MS = 3000
const POLL_MS = 5000
const checkStatus = async () => {
const openLink = computed(() => (ip.value ? `http://${ip.value}` : '#'))
async function checkStatus () {
try {
const res = await $fetch(`${window.location.origin}/api/status?name=${name}`, {
const res = await $fetch(`${window.location.origin}/api/status?name=${encodeURIComponent(name)}`, {
method: 'GET',
cache: 'no-store' // Browser-Cache umgehen
cache: 'no-store'
})
status.value = res.status
ip.value = res.ip ?? ip.value
// Optional: wenn der Container "aus" ist, hier Start triggern (API abhängig)
// if (res.status === 'stopped' || res.status === 'not_found') {
// await $fetch(`${window.location.origin}/api/start?name=${name}`, { method: 'POST' })
// status.value = 'starting'
// }
if (res.ip) ip.value = res.ip
if (res.status === 'ready') {
// Polling nur bei success beenden
if (interval.value) clearInterval(interval.value)
loading.value = false
ip.value = res.ip
// Redirect-Logik: wenn redirect gesetzt -> dahin; sonst zur Root oder zur IP
if (redirect) {
window.location.href = redirect.toString();
// Prefer bridge handoff if we have an id; otherwise, just open container root.
if (handoff) {
const bridge = new URL(`${window.location.origin}/api/handoff/post`)
bridge.searchParams.set('name', name)
bridge.searchParams.set('handoff', handoff)
bridge.searchParams.set('path', safePath)
// Replace to avoid creating a back entry with sensitive navigation
window.location.replace(bridge.toString())
} else if (ip.value) {
window.location.replace(`http://${ip.value}`)
} else {
// Entweder auf die IP oder auf die Host-Root
// window.location.href = `http://${ip.value}`
window.location.href = `http://${window.location.host}`
window.location.replace(`http://${window.location.host}`)
}
} else {
// solange nicht ready: weiterladen anzeigen
loading.value = true
}
} catch (error) {
@ -72,17 +81,15 @@ const checkStatus = async () => {
if (interval.value) clearInterval(interval.value)
// nach kurzer Pause zurück zur App (Redirect-Param übernehmen)
// Bounce back to app without leaking anything sensitive
setTimeout(() => {
router.replace(`/app/?auth=ok&redirect=${redirect ?? ''}`)
router.replace(`/app/`)
}, 5000)
}
}
onMounted(() => {
checkStatus()
// WICHTIG: Intervall NICHT im checkStatus selbst löschen,
// sondern nur bei ready/error oder beim Unmount.
interval.value = setInterval(checkStatus, POLL_MS)
})