feat(server): 集成静态文件服务并优化开发环境配置

- 添加 koa-static 中间件以支持静态资源访问
- 更新 package.json 引入 nodemon 用于服务热重载- 调整项目结构,将前端代码移至 module/web 目录下
- 修改图片引用路径适配新目录结构
- 更新主入口文件引入路由模块的方式- 配置 Vite 构建工具替换原有构建方式- 移除 Turbo依赖并使用 concurrently 管理多进程开发任务- 更新根目录 package.json 的脚本命令指向新的开发启动逻辑
This commit is contained in:
2025-10-19 22:40:56 +08:00
parent 5f4858e991
commit 57aff59b45
20 changed files with 43 additions and 56 deletions

View File

@@ -1,6 +1,7 @@
import Koa from 'koa';
import Router from 'koa-router';
import config from "./config/index.js"
import koaStatic from 'koa-static';
const app = new Koa();
const router = new Router();
@@ -19,9 +20,10 @@ router.get('/api/config', (ctx) => {
})
app.use(router.routes());
app.use(router.allowedMethods());
app.use(koaStatic('/www'))
const PORT = process.env.PORT || 3001;
app.listen(PORT, () => {
console.log(`Koa server is running on port ${PORT}`);
});
});

View File

@@ -6,10 +6,11 @@
"type": "module",
"scripts": {
"start": "node index.js",
"dev": "node index.js"
"dev": "nodemon index.js"
},
"dependencies": {
"koa": "^2.15.0",
"koa-router": "^12.0.0"
"koa-router": "^12.0.0",
"koa-static": "^5.0.0"
}
}
}

View File

@@ -18,6 +18,6 @@
</head>
<body oncontextmenu="return false" ondragstart="return false">
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
<script type="module" src="/module/web/src/main.js"></script>
</body>
</html>

View File

@@ -1,8 +1,19 @@
{
"name": "web",
"name": "chuanqi-web",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "cd ../.. && pnpm dev",
"build": "cd ../.. && pnpm build"
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"axios": "^1.12.2",
"vue": "^3.5.21",
"vue-router": "^4.5.1"
},
"devDependencies": {
"@vitejs/plugin-vue": "^6.0.1",
"vite": "^7.1.7"
}
}

View File

@@ -73,18 +73,6 @@ $directions: (
.w50v{width: 50vw!important;}
.h50v{height: 50vh!important;}
.no-devices{
background-image: url("../assets/no-devices.png");
background-repeat: no-repeat;
background-position: 50% 38.2%; /* 纵轴38.2% */
background-size: auto 40%;
text-align: center;
color: #888;
display: flex;
justify-content: center; /* 水平居中 */
padding-top: calc( 45% + 16px);
}
/* Chrome, Edge, Safari, Opera */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {

View File

Before

Width:  |  Height:  |  Size: 496 B

After

Width:  |  Height:  |  Size: 496 B

View File

@@ -1,7 +1,7 @@
import {createApp} from 'vue'
import './style.css'
import App from './App.vue'
import router from './router'
import router from './router/index.js'
// window.external?.OpenGameWindowNew(window.location.href, '', '', '', false);
document.onkeydown = document.onkeyup = document.onkeypress = function (e) {

View File

@@ -31,7 +31,7 @@ function handleLogin() {
<a id="submitButton" class="button fit" @click="handleLogin"> </a>
<div style="display:flex;justify-content:center;gap:8px;font-size:12px">
<div style="display:flex;align-items:center;flex-direction:column;gap:4px;cursor:pointer" id="linuxdoConnect">
<img src="/static/img/linuxdo_logo.png" style="width:60px;height:60px" alt="Linux.Do登录"/>
<img src="/img/linuxdo_logo.png" style="width:60px;height:60px" alt="Linux.Do登录"/>
<div>Linux.do</div>
</div>
</div>
@@ -46,7 +46,7 @@ function handleLogin() {
<style scoped>
.gamebg {
background-image: url("/static/img/login_bg.jpg");
background-image: url("/img/login_bg.jpg");
}
</style>

View File

@@ -1,30 +1,18 @@
{
"name": "chuanqi-web",
"private": true,
"version": "0.0.0",
"name": "chuanqi-qycq-web",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"dev": "vite",
"dev:server": "pnpm --filter chuanqi-server dev",
"start:server": "pnpm --filter chuanqi-server start",
"build": "vite build",
"preview": "vite preview",
"turbo": "turbo run dev"
},
"dependencies": {
"axios": "^1.12.2",
"vue": "^3.5.21",
"vue-router": "^4.5.1"
"dev": "node scripts/dev.js",
"build": "pnpm -r run build"
},
"keywords": [],
"author": "Kubbo",
"license": "ISC",
"packageManager": "pnpm@10.18.2",
"devDependencies": {
"@vitejs/plugin-vue": "^6.0.1",
"turbo": "^2.5.8",
"vite": "^7.1.7"
},
"pnpm": {
"workspace": [
"server"
]
},
"packageManager": "pnpm@10.18.2"
"concurrently": "^9.2.1"
}
}

6
scripts/dev.js Normal file
View File

@@ -0,0 +1,6 @@
import concurrently from 'concurrently';
const scope = [
{"name": "WEB", "command": "pnpm --filter ./module/web dev"},
{"name": "HTTP", "command": "pnpm --filter ./module/server dev"}
]
concurrently(scope, {"prefix": "[{name}]", "killOthers": ["failure", "success"], prefixColors: 'auto'})

View File

@@ -1,9 +0,0 @@
{
"$schema": "https://turbo.build/schema.json",
"tasks": {
"dev": {
"cache": false,
"persistent": true
}
}
}