Initial template: Vue 3 + FastAPI + SQLite full-stack with K8s deployment
Some checks failed
Deploy Production / test (push) Failing after 1s
Deploy Production / deploy (push) Has been skipped
Test / unit-test (push) Failing after 1s
Test / e2e-test (push) Has been skipped
Test / build-check (push) Failing after 1s

Extracted from oil project — business logic removed, auth/db/deploy infrastructure
generalized with APP_NAME placeholders.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-06 22:13:06 +00:00
commit d19183923c
32 changed files with 1350 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
import { defineConfig } from 'cypress'
export default defineConfig({
e2e: {
baseUrl: 'http://localhost:5173',
supportFile: 'cypress/support/e2e.js',
specPattern: 'cypress/e2e/**/*.cy.{js,ts}',
viewportWidth: 1280,
viewportHeight: 800,
video: true,
videoCompression: false,
},
})

View File

@@ -0,0 +1,10 @@
describe('Smoke test', () => {
it('loads the home page', () => {
cy.visit('/')
cy.contains('Welcome')
})
it('health check API responds', () => {
cy.request('GET', '/api/health').its('status').should('eq', 200)
})
})

View File

@@ -0,0 +1,23 @@
Cypress.on('uncaught:exception', (err) => {
if (err.message.includes('ResizeObserver')) return false
return true
})
// Login as admin via token injection
Cypress.Commands.add('loginAsAdmin', () => {
cy.request('GET', '/api/users').then((res) => {
const admin = res.body.find(u => u.role === 'admin')
if (admin) {
cy.window().then(win => {
win.localStorage.setItem('auth_token', admin.token)
})
}
})
})
// Login with a specific token
Cypress.Commands.add('loginWithToken', (token) => {
cy.window().then(win => {
win.localStorage.setItem('auth_token', token)
})
})

12
frontend/index.html Normal file
View File

@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>

29
frontend/package.json Normal file
View File

@@ -0,0 +1,29 @@
{
"name": "frontend",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"cy:open": "cypress open",
"cy:run": "cypress run",
"test:e2e": "cypress run",
"test:unit": "vitest run",
"test": "vitest run && cypress run"
},
"dependencies": {
"pinia": "^2.3.1",
"vue": "^3.5.32",
"vue-router": "^4.6.4"
},
"devDependencies": {
"@vitejs/plugin-vue": "^6.0.5",
"@vue/test-utils": "^2.4.6",
"cypress": "^15.13.0",
"jsdom": "^29.0.1",
"vite": "^8.0.4",
"vitest": "^4.1.2"
}
}

41
frontend/src/App.vue Normal file
View File

@@ -0,0 +1,41 @@
<template>
<div class="app">
<header class="app-header">
<div class="header-inner">
<h1 class="header-title">App</h1>
<nav class="nav-tabs">
<router-link
v-for="tab in tabs"
:key="tab.to"
:to="tab.to"
class="nav-tab"
active-class="active"
>{{ tab.label }}</router-link>
</nav>
<div class="header-right">
<template v-if="auth.isLoggedIn">
<span class="user-name">{{ auth.user.display_name || auth.user.username }}</span>
<button class="btn-link" @click="auth.logout()">退出</button>
</template>
<template v-else>
<router-link to="/login" class="btn-link">登录</router-link>
</template>
</div>
</div>
</header>
<main class="app-main">
<router-view />
</main>
</div>
</template>
<script setup>
import { useAuthStore } from './stores/auth'
const auth = useAuthStore()
auth.initToken()
const tabs = [
{ to: '/', label: '首页' },
]
</script>

View File

@@ -0,0 +1,149 @@
/* ── Design tokens ─────────────────────────────────── */
:root {
--color-primary: #4a7c59;
--color-primary-dark: #3a6349;
--color-accent: #c9a84c;
--color-bg: #faf6f0;
--color-bg-card: #ffffff;
--color-text: #333333;
--color-text-muted: #888888;
--color-border: #e0d8cc;
--color-danger: #d32f2f;
--shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
--shadow-md: 0 2px 8px rgba(0, 0, 0, 0.12);
--radius: 8px;
--font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', sans-serif;
}
/* ── Reset ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: var(--font-sans);
background: var(--color-bg);
color: var(--color-text);
line-height: 1.6;
}
/* ── Layout ───────────────────────────────────────── */
.app-header {
background: var(--color-primary);
color: white;
padding: 12px 20px;
}
.header-inner {
max-width: 1200px;
margin: 0 auto;
display: flex;
align-items: center;
gap: 20px;
}
.header-title {
font-size: 18px;
font-weight: 600;
white-space: nowrap;
}
.nav-tabs {
display: flex;
gap: 4px;
flex: 1;
}
.nav-tab {
padding: 6px 14px;
border-radius: var(--radius);
color: rgba(255, 255, 255, 0.8);
text-decoration: none;
font-size: 14px;
transition: background 0.2s;
}
.nav-tab:hover { background: rgba(255, 255, 255, 0.15); }
.nav-tab.active { background: rgba(255, 255, 255, 0.25); color: white; }
.header-right {
display: flex;
align-items: center;
gap: 10px;
font-size: 14px;
white-space: nowrap;
}
.app-main {
max-width: 1200px;
margin: 20px auto;
padding: 0 20px;
}
/* ── Components ───────────────────────────────────── */
.page { padding: 20px 0; }
.btn-primary {
background: var(--color-primary);
color: white;
border: none;
padding: 8px 20px;
border-radius: var(--radius);
cursor: pointer;
font-size: 14px;
}
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-link {
background: none;
border: none;
color: inherit;
cursor: pointer;
text-decoration: underline;
font-size: inherit;
}
.form-group {
margin-bottom: 14px;
}
.form-group label {
display: block;
font-size: 14px;
margin-bottom: 4px;
color: var(--color-text-muted);
}
.form-group input {
width: 100%;
padding: 8px 12px;
border: 1px solid var(--color-border);
border-radius: var(--radius);
font-size: 14px;
}
.error { color: var(--color-danger); font-size: 13px; }
.card {
background: var(--color-bg-card);
border-radius: var(--radius);
box-shadow: var(--shadow-sm);
padding: 16px;
}
.toast {
position: fixed;
top: 20px;
right: 20px;
background: #333;
color: white;
padding: 10px 20px;
border-radius: var(--radius);
z-index: 9999;
font-size: 14px;
}
/* ── Responsive ───────────────────────────────────── */
@media (max-width: 640px) {
.header-inner { flex-wrap: wrap; }
.nav-tabs { order: 3; width: 100%; overflow-x: auto; }
}

View File

@@ -0,0 +1,51 @@
const API_BASE = '' // same origin, uses vite proxy in dev
export function getToken() {
return localStorage.getItem('auth_token') || ''
}
export function setToken(token) {
if (token) localStorage.setItem('auth_token', token)
else localStorage.removeItem('auth_token')
}
function buildHeaders(extra = {}) {
const headers = { 'Content-Type': 'application/json', ...extra }
const token = getToken()
if (token) headers['Authorization'] = 'Bearer ' + token
return headers
}
async function request(path, opts = {}) {
const headers = buildHeaders(opts.headers)
const res = await fetch(API_BASE + path, { ...opts, headers })
return res
}
async function requestJSON(path, opts = {}) {
const res = await request(path, opts)
if (!res.ok) {
let msg = `${res.status}`
try {
const body = await res.json()
msg = body.detail || body.message || msg
} catch {}
const err = new Error(msg)
err.status = res.status
throw err
}
return res.json()
}
function apiFn(path, opts = {}) {
return request(path, opts)
}
apiFn.raw = request
apiFn.get = (path) => requestJSON(path)
apiFn.post = (path, body) => requestJSON(path, { method: 'POST', body: JSON.stringify(body) })
apiFn.put = (path, body) => requestJSON(path, { method: 'PUT', body: JSON.stringify(body) })
apiFn.del = (path) => requestJSON(path, { method: 'DELETE' })
apiFn.delete = (path) => requestJSON(path, { method: 'DELETE' })
export const api = apiFn

10
frontend/src/main.js Normal file
View File

@@ -0,0 +1,10 @@
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'
import './assets/styles.css'
const app = createApp(App)
app.use(createPinia())
app.use(router)
app.mount('#app')

View File

@@ -0,0 +1,21 @@
import { createRouter, createWebHistory } from 'vue-router'
const routes = [
{
path: '/',
name: 'Home',
component: () => import('../views/Home.vue'),
},
{
path: '/login',
name: 'Login',
component: () => import('../views/Login.vue'),
},
]
const router = createRouter({
history: createWebHistory(),
routes,
})
export default router

View File

@@ -0,0 +1,80 @@
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import { api, setToken } from '../composables/useApi'
const DEFAULT_USER = {
id: null,
role: 'viewer',
username: 'anonymous',
display_name: '匿名',
}
export const useAuthStore = defineStore('auth', () => {
const token = ref(localStorage.getItem('auth_token') || '')
const user = ref({ ...DEFAULT_USER })
const isLoggedIn = computed(() => user.value.id !== null)
const isAdmin = computed(() => user.value.role === 'admin')
const canEdit = computed(() =>
['editor', 'admin'].includes(user.value.role)
)
async function initToken() {
const params = new URLSearchParams(window.location.search)
const urlToken = params.get('token')
if (urlToken) {
token.value = urlToken
setToken(urlToken)
const url = new URL(window.location)
url.searchParams.delete('token')
window.history.replaceState({}, '', url)
}
if (token.value) {
await loadMe()
}
}
async function loadMe() {
try {
const data = await api.get('/api/me')
user.value = {
id: data.id,
role: data.role,
username: data.username,
display_name: data.display_name,
}
} catch {
logout()
}
}
async function login(username, password) {
const data = await api.post('/api/login', { username, password })
token.value = data.token
setToken(data.token)
await loadMe()
}
async function register(username, password, displayName) {
const data = await api.post('/api/register', {
username,
password,
display_name: displayName,
})
token.value = data.token
setToken(data.token)
await loadMe()
}
function logout() {
token.value = ''
setToken(null)
user.value = { ...DEFAULT_USER }
}
return {
token, user,
isLoggedIn, isAdmin, canEdit,
initToken, loadMe, login, register, logout,
}
})

View File

@@ -0,0 +1,6 @@
<template>
<div class="page">
<h2>Welcome</h2>
<p>App is running.</p>
</div>
</template>

View File

@@ -0,0 +1,39 @@
<template>
<div class="page login-page">
<h2>登录</h2>
<form @submit.prevent="handleLogin">
<div class="form-group">
<label>用户名</label>
<input v-model="username" required />
</div>
<div class="form-group">
<label>密码</label>
<input v-model="password" type="password" required />
</div>
<p v-if="error" class="error">{{ error }}</p>
<button type="submit" class="btn-primary">登录</button>
</form>
</div>
</template>
<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useAuthStore } from '../stores/auth'
const auth = useAuthStore()
const router = useRouter()
const username = ref('')
const password = ref('')
const error = ref('')
async function handleLogin() {
error.value = ''
try {
await auth.login(username.value, password.value)
router.push('/')
} catch (e) {
error.value = e.message
}
}
</script>

18
frontend/vite.config.js Normal file
View File

@@ -0,0 +1,18 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
export default defineConfig({
plugins: [vue()],
server: {
proxy: {
'/api': 'http://localhost:8000',
}
},
build: {
outDir: 'dist'
},
test: {
environment: 'jsdom',
globals: true,
}
})