Last active
August 29, 2015 14:02
-
-
Save v0lkan/12aba89e561aee2b1115 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = require('express')(), | |
server = require('http').Server(app), | |
io = require('engine.io').attach(server); | |
// Use this middleware to workaround "Access-Control-Allow-Origin" errors on the client. | |
app.use(function (req, res, next) { | |
res.setHeader('Access-Control-Allow-Origin', "http://theWebsiteThatOpensSocketConnection.com"); | |
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE'); | |
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type'); | |
res.setHeader('Access-Control-Allow-Credentials', 'true'); | |
next(); | |
} | |
); | |
// Proxied by NGINX. See below. | |
server.listen(3045); | |
// Don't forget to set up NGINX properly to allow HTTP upgrades, | |
// Otherwise engine.io will ALWAYS use long polling, which is not efficient. | |
// | |
// NGINX Configuration: | |
/* | |
server { | |
listen 80; | |
server_name pipe.awesomewebsocketserver.com; | |
location / { | |
proxy_pass http://127.0.0.1:3045; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "upgrade"; | |
proxy_set_header Host $host; | |
} | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment