Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: make web_microphone_websocket work outside localhost #27

Open
comodoro opened this issue Jan 9, 2022 · 3 comments
Open

Comments

@comodoro
Copy link
Contributor

comodoro commented Jan 9, 2022

The web_microphone_websocket example works for localhost, but on a domain there were CORS errors from the socket.io code, e.g. Chrome:

Access to XMLHttpRequest at 'https://example.com:4000/socket.io/?EIO=3&transport=polling&t=Nu-iT4E' from origin 'https://example.com.cz:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Several recipes from SO and the socket.io docs did not work, perhaps someone with better JS knowledge might help.

@neural-loop
Copy link

Hi Comodoro are you still looking for this

@comodoro
Copy link
Contributor Author

comodoro commented Mar 13, 2022 via email

@neural-loop
Copy link

neural-loop commented Mar 13, 2022

Try this in the server.js:

const app = http.createServer(function (req, res) {
	const headers = {
		'Access-Control-Allow-Origin': '*',
		'Access-Control-Max-Age': 2592000, // 30 days
		/** add other headers as per requirement */
	};
	res.writeHead(200, headers);
	res.write('STT');
	res.end();
});

const io = socketIO(app, {});
io.set('origins', '*:*');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants