diff --git a/server/public/index.html b/server/public/index.html index 103d35d..f6b58be 100644 --- a/server/public/index.html +++ b/server/public/index.html @@ -20,7 +20,7 @@ const data = JSON.parse(event.data); if (data.type === 'file') { // 处理文件消息,例如显示文件下载链接 - const fileUrl = data.url; + const fileUrl = window.location.origin + data.url; const fileLink = document.createElement('a'); fileLink.href = fileUrl; fileLink.target = '_blank'; diff --git a/server/server.js b/server/server.js index c02a47e..04059e3 100644 --- a/server/server.js +++ b/server/server.js @@ -29,7 +29,7 @@ app.use(express.static(path.join(__dirname, 'public'))); // 处理文件上传 app.post('/upload', upload.single('file'), (req, res) => { - const fileUrl = `http://localhost:3000/uploads/${req.file.filename}`; + const fileUrl = `/uploads/${req.file.filename}`; wss.clients.forEach(function each(client) { if (client.readyState === WebSocket.OPEN) { client.send(JSON.stringify({ type: 'file', url: fileUrl }));