【发布时间】:2021-11-26 21:18:15
【问题描述】:
这是倒计时项目,我使用https://www.npmjs.com/package/timesync进行时间同步
server.js
const app = require('express')();
const http = require('http').Server(app);
const io = require('socket.io')(http);
const port = process.env.PORT || 3000;
var timesyncServer = require('timesync/server');
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
app.get('/admin', (req, res) => {
res.sendFile(__dirname + '/admin.html');
});
io.on('connection', (socket) => {
console.log('success-connection')
socket.on('chat message', msg => {
io.emit('chat message', msg);
});
});
http.listen(port, () => {
console.log(`Socket.IO server running at http://localhost:${port}/`);
});
// handle timesync requests
app.use('/timesync', timesyncServer.requestHandler);
我尝试了一些方法,但没有奏效。
我收到此错误消息:
GET http://localhost:3000/script.js net::ERR_ABORTED 404(未找到)
这是我的项目:
File-strucure
【问题讨论】:
-
在此处提供您的 script.js
-
我的 script.js 中没有任何内容,只有 console.log(1)。我试图在我的 index.html 页面上像这样 包含它。
标签: javascript node.js express sockets socket.io