Saturday 13 May 2017

The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' error in socket.io

I am currently learning Redux and am following along this tutorial http://teropa.info/blog/2015/09/10/full-stack-redux-tutorial.html

I am relatively new to servers and the backend and encountered the error indicated in the Title when trying to link up my server with the front end using socket.io.

I have tried setting the origins options for the server using:

const io = new Server().attach(8090, {
    origins: 'http://localhost:8080'
});

but did not manage to resolve the issue.

My server side code for as follows:

server.js:

import Server from 'socket.io';

export default function startServer(store) {
    const io = new Server().attach(8090);

    store.subscribe(
        () => io.emit('state', store.getState().toJS())
    );

    io.on('connection', (socket) => {
        socket.emit(('state', store.getState().toJS()));
        socket.on('action', store.dispatch.bind(store));
    });
}

index.js:

import makeStore from './src/store';
import startServer from './src/server';

export const store = makeStore();

startServer(store);

On the client application I have done the following: index.js:

import io from 'socket.io-client';

const socket = io(`${location.protocol}//${location.hostname}:8090`);



via Joshua

No comments:

Post a Comment