vue-socket.io + nodejs实现实时通信,私聊,群聊
写这篇文章主要是记录自己在学习中踩过的坑,目前技术不太成熟,有些不合理的地方还请大佬们指出,谢谢
直接粘代码吧
const app = require('express')();
const http = require('http');
const socketio = require('socket.io');
const server = http.createServer(app);
//设置允许跨域
app.all('*', function (req, res, next) {
res.header("Access-Control-Allow-Credentials", true)
res.header("Access-Control-Allow-Origin", "*")
res.header("Access-Control-Allow-Headers", "X-Requested-With")
res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS")
res.header("X-Powered-By", ' 3.2.1')
res.header("Content-Type", "application/json;charset=utf-8")
next(