1 Star 0 Fork 32

liang1024/nav

forked from xiejiahe/nav 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
server.js 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
xjh22222228 提交于 2024-08-01 20:30 . chore: add dep
// Copyright @ 2018-present xiejiahe. All rights reserved. MIT license.
// See https://github.com/xjh22222228/nav
// 启动端口
const PORT = 7777
const DEPLOY_DIR = process.cwd()
const express = require('express')
const cors = require('cors')
const fs = require('node:fs')
const { execSync } = require('child_process')
// 创建 Express 应用实例
const app = express()
app.use(express.static('dist'))
app.get('/server', (req, res) => {
console.log('正在部署...')
let gitDir = ''
try {
gitDir = execSync('which git').toString()
} catch (error) {
return res.send('找不到 git 命令位置')
}
if (!fs.existsSync(DEPLOY_DIR)) {
return res.send(`仓库目录不存在: ${DEPLOY_DIR}`)
}
try {
const res = execSync(
`cd ${DEPLOY_DIR} && npm run pull && npm run build`
).toString()
} catch (error) {
console.log('Failed:', error.message)
return res?.send?.(error.message)
}
console.log('OK')
res?.send?.('OK')
})
app.use(
cors({
origin: '*',
methods: '*',
allowedHeaders: '*',
})
)
app.listen(PORT, () => {
console.log(`Server is running on port :${PORT}`)
console.log(`Directory: ${DEPLOY_DIR}`)
})
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/lzge/nav.git
git@gitee.com:lzge/nav.git
lzge
nav
nav
main

搜索帮助