Browse Source

socketio handlePreflightRequest

push-params
Evan Feenstra 5 years ago
parent
commit
43ed26d67e
  1. 12
      api/utils/socket.ts
  2. 12
      dist/api/utils/socket.js
  3. 2
      dist/api/utils/socket.js.map

12
api/utils/socket.ts

@ -10,7 +10,17 @@ let io: any
export function connect(server) {
// srvr = new WebSocket.Server({ server, clientTracking:true })
io = socketio(server, {origins: '*:*'});
io = socketio(server, {
handlePreflightRequest: (req, res) => {
const headers = {
"Access-Control-Allow-Headers": "Content-Type, Accept, x-user-token, X-Requested-With",
"Access-Control-Allow-Origin": req.headers.origin, //or the specific origin you want to give access to,
"Access-Control-Allow-Credentials": true
};
res.writeHead(200, headers);
res.end();
}
});
io.use(async (socket, next) => {
let userToken = socket.handshake.headers['x-user-token'];
const isValid = await isValidToken(userToken)

12
dist/api/utils/socket.js

@ -17,7 +17,17 @@ let io;
// let srvr: any
function connect(server) {
// srvr = new WebSocket.Server({ server, clientTracking:true })
io = socketio(server, { origins: '*:*' });
io = socketio(server, {
handlePreflightRequest: (req, res) => {
const headers = {
"Access-Control-Allow-Headers": "Content-Type, Accept, x-user-token, X-Requested-With",
"Access-Control-Allow-Origin": req.headers.origin,
"Access-Control-Allow-Credentials": true
};
res.writeHead(200, headers);
res.end();
}
});
io.use((socket, next) => __awaiter(this, void 0, void 0, function* () {
let userToken = socket.handshake.headers['x-user-token'];
const isValid = yield isValidToken(userToken);

2
dist/api/utils/socket.js.map

@ -1 +1 @@
{"version":3,"file":"socket.js","sourceRoot":"","sources":["../../../api/utils/socket.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sCAAgC;AAChC,iCAAgC;AAEhC,kCAAkC;AAClC,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AAEtC,IAAI,EAAO,CAAA;AACX,gBAAgB;AAEhB,SAAgB,OAAO,CAAC,MAAM;IAC5B,+DAA+D;IAE/D,EAAE,GAAG,QAAQ,CAAC,MAAM,EAAE,EAAC,OAAO,EAAE,KAAK,EA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