feat: 完善全栈 Dashboard 项目 - UI优化、Docker支持、账单系统等
This commit is contained in:
@@ -1,16 +1,22 @@
|
||||
import express from 'express'
|
||||
import cors from 'cors'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
import fs from 'fs'
|
||||
import sitesRouter from './routes/sites.js'
|
||||
import authRouter from './routes/auth.js'
|
||||
import proxyRouter from './routes/proxy.js'
|
||||
import billingRouter from './routes/billing.js'
|
||||
import { ensureChineseFont } from './utils/font.js'
|
||||
|
||||
const app = express()
|
||||
const PORT = 3001
|
||||
const PORT = Number(process.env.PORT) || 3001
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
||||
|
||||
app.use(cors())
|
||||
app.use(express.json())
|
||||
|
||||
// API routes
|
||||
app.get('/api/health', (_req, res) => {
|
||||
res.json({ success: true, message: 'NewAPI Dashboard BFF running' })
|
||||
})
|
||||
@@ -20,8 +26,26 @@ app.use('/api/auth', authRouter)
|
||||
app.use('/proxy', proxyRouter)
|
||||
app.use('/api/billing', billingRouter)
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`BFF server running on http://localhost:${PORT}`)
|
||||
})
|
||||
// Production: serve frontend static files from dist/
|
||||
const distPath = path.join(__dirname, '..', 'dist')
|
||||
if (fs.existsSync(path.join(distPath, 'index.html'))) {
|
||||
app.use(express.static(distPath))
|
||||
// SPA fallback: any non-API GET request returns index.html
|
||||
app.get('*', (_req, res) => {
|
||||
res.sendFile(path.join(distPath, 'index.html'))
|
||||
})
|
||||
}
|
||||
|
||||
export default app
|
||||
// Download Chinese font then start server
|
||||
ensureChineseFont()
|
||||
.then(() => {
|
||||
app.listen(PORT, '0.0.0.0', () => {
|
||||
console.log(`BFF server running on http://0.0.0.0:${PORT}`)
|
||||
})
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Font initialization failed:', err.message)
|
||||
app.listen(PORT, '0.0.0.0', () => {
|
||||
console.log(`BFF server running on http://0.0.0.0:${PORT} (font unavailable)`)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user