60 lines
1.8 KiB
JavaScript
60 lines
1.8 KiB
JavaScript
const express = require('express');
|
|
const path = require('path');
|
|
const app = express();
|
|
|
|
// 设置静态文件目录
|
|
app.use(express.static(path.join(__dirname)));
|
|
|
|
// 下载路由
|
|
app.get('/download', (req, res) => {
|
|
const filePath = path.join(__dirname, 'EST-DSX Setup 1.2.0.exe');
|
|
res.download(filePath, (err) => {
|
|
if (err) {
|
|
res.status(500).send('下载文件时发生错误');
|
|
}
|
|
});
|
|
});
|
|
|
|
// 主页
|
|
app.get('/', (req, res) => {
|
|
res.send(`
|
|
<html>
|
|
<head>
|
|
<title>文件下载</title>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
height: 100vh;
|
|
margin: 0;
|
|
background-color: #f0f0f0;
|
|
}
|
|
.download-btn {
|
|
padding: 15px 30px;
|
|
font-size: 18px;
|
|
background-color: #4CAF50;
|
|
color: white;
|
|
border: none;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
text-decoration: none;
|
|
}
|
|
.download-btn:hover {
|
|
background-color: #45a049;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<a href="/download" class="download-btn">下载 EST-DSX Setup</a>
|
|
</body>
|
|
</html>
|
|
`);
|
|
});
|
|
|
|
// 启动服务器
|
|
const PORT = 3000;
|
|
app.listen(PORT, () => {
|
|
console.log(`服务器运行在 http://localhost:${PORT}`);
|
|
}); |