获取错误:当我在cpanel上部署socketio app.js时,GET 404(未找到)



我试图在我的主机cpanel上部署一个nodejs应用程序,但每当我尝试运行它时,html就会打开,但数据没有从nodejs发送到客户端,我只是在控制台上收到了这个错误

index.js:83
GEThttp://streamedbot.xyz/socket.io/?EIO=3&transport=轮询&t=OFQdTfs 404(未找到(

这是我的app.js

const fetchP2PData = require("./fetchP2PData.js");
const app = require("express")();
const path = require("path");
const Datastore = require("nedb");
// const http = require("http").createServer(app);
// const io = require("socket.io")(http);
const { createServer } = require('http')
const { Server } = require('socket.io')

const server = createServer(app)
const io = new Server(server, {
cors: { 
origin: "*",
methods: ["GET", "POST"],
credentials: false,
transports: ['websocket', 'polling'],
},
allowEIO3: true
})
app.get('/bkpapp/', function(req,res){
res.sendFile(__dirname + '/index.html');
});
let prices = [];
let openingPrice = 0 ;
const priceDb = new Datastore("./price.db");
priceDb.loadDatabase();
priceDb.find({}, { time: 1, value: 1, _id: 0 }, function (err, docs) {
docs.reverse();
prices = docs;
console.log(prices);
});
setInterval(function () {
(async function () {

let totalPrices = []; 
const firstPage = await fetchP2PData(1, "ETB", "BUY", "USDT", null);
if (firstPage && firstPage.success) {
const totalPages = Math.ceil(firstPage.total / 20);
const pagesToRun = new Array(totalPages - 1).fill(null);
const totalElements = await pagesToRun.reduce(async (prev, _, idx) => {
const accData = await prev;
const page = idx + 2;
const pageResult = await fetchP2PData(page, "ETB", "BUY", "USDT", null);
if (pageResult && pageResult.success) {
return [...accData, ...pageResult.data];
}
return accData;
}, Promise.resolve(firstPage.data));
totalElements.map((obj) => {
totalPrices.push(parseFloat(obj.adv.price));
});
}

let currentPrice = ((totalPrices[0]+totalPrices[1]+totalPrices[2]+totalPrices[3]+totalPrices[4]+totalPrices[5]+totalPrices[6]+totalPrices[7]+totalPrices[8]+totalPrices[9]+totalPrices[10])/11)-3.95;
const d = new Date();
if(d.getHours() == 00 && d.getMinutes() == 00){
openingPrice = currentPrice;
}
let dailyPercentage = ((currentPrice - openingPrice)/openingPrice)*(100)
prices.push({ time: d.getTime()/1000, value: (((totalPrices[0]+totalPrices[1]+totalPrices[2]+totalPrices[3]+totalPrices[4]+totalPrices[5]+totalPrices[6]+totalPrices[7]+totalPrices[8]+totalPrices[9]+totalPrices[10])/11)-3.95)})

io.on('connection', sock => {

})
if(totalPrices != null){
io.sockets.emit('price', prices)
priceDb.insert({ time: d.getTime()/1000, value: (((totalPrices[0]+totalPrices[1]+totalPrices[2]+totalPrices[3]+totalPrices[4]+totalPrices[5]+totalPrices[6]+totalPrices[7]+totalPrices[8]+totalPrices[9]+totalPrices[10])/11)-3.95)});
io.sockets.emit('dailyPercentage', dailyPercentage)
}

// io.sockets.on('connection', function (socket){
//     io.sockets.emit('price', { time: d.getTime(), value: totalPrices[0] });
// })


console.log(prices);
})();
}, 10000);
server.listen(3000, function(){
console.log('listening to 80')
})

似乎有必要合并io实例和服务器实例。

根据socket.io文档,您可以通过添加行io.attach(server);来合并这两个实例。

socket.io文档