Nginx server returns cors error when trying to acess peerserver port on same server, citing cors error

0

I'm having an issue with a library called peerjs Which worked on my localhost testing server, but had some growing pains working with nginx reverse proxies. Here are some things I did, but I'm still getting a CORS error when trying to access the peerjs server.(but I don't think that peerjs is the problem here, this could possibly happen with anything)

  • used "ufw allow 8696"(the port that peerserver uses)
  • used the CORS library with my nodejs server, as recommended by a different stackoverflow post*
  • Altered my nginx config to allow CORS on all paths**

You can see the error yourself at https://jakesandbox.com/ChatPal But I still get this CORS error:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the    remote resource at https://jakesandbox.com:8696/ChatPal/cpl/peerjs/id?ts=15558555858600.2456313902975088. (Reason: CORS request did not succeed).

Are there any fixes I can perform to allow this request to the same server?

*

var path = require('path');
var express = require('express');
var ExpressPeerServer = require('peer').ExpressPeerServer;
var routes = require('./routes');
var app = express();
var cors = require('cors');
app.use(cors());
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', routes);
var server = require('http').createServer(app);
var peerserver = ExpressPeerServer(server);
app.use('/ChatPal/cpl', peerserver);
server.listen(8696);
app.listen(6767);
console.log('Listening on 6767');

**

 set $cors_origin "";
set $cors_cred   "";
set $cors_header "";
set $cors_method "";

if ($http_origin ~ '^https?://(localhost|jakesandbox.com\.com)$') {
        set $cors_origin $http_origin;
        set $cors_cred   true;
        set $cors_header $http_access_control_request_headers;
        set $cors_method $http_access_control_request_method;
}

add_header Access-Control-Allow-Origin      $cors_origin;
add_header Access-Control-Allow-Credentials $cors_cred;
add_header Access-Control-Allow-Headers     $cors_header;
add_header Access-Control-Allow-Methods     $cors_method;

p.s. I will include any information I neglected to include

p.p.s. This post was migrated from https://serverfault.com/questions/963927/nginx-peerjs-server-returns-cors-error-when-trying-to-acess-peerserver-port?noredirect=1#comment1254133_963927 for being off-topic, I'm pretty sure that this qualifies as personal networking, as this is a hobby server I have in my room, and the "code" I wrote is more of a configuration file than anything.

Jake t

Posted 2019-04-20T23:16:06.037

Reputation: 1

No answers