Skip to content

Instantly share code, notes, and snippets.

@beardlessman
Last active May 2, 2019 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beardlessman/04bc039efab81daf0601575385aaa331 to your computer and use it in GitHub Desktop.
Save beardlessman/04bc039efab81daf0601575385aaa331 to your computer and use it in GitHub Desktop.
// SERVER
const axios = require('axios');
module.exports = () => {
const io = require('socket.io')();
io.listen(3000);
io.on('connection', function(socket) {
socket.on('SEARCH_REQUEST', query => {
axios
.get(`http://www.omdbapi.com/?s=${query}&apikey=a27a9b08`)
.then(res => {
socket.emit('SEARCH_RESULT', res.data);
})
.catch(err => console.log(err));
return;
});
});
};
// CLIENT
import * as io from 'socket.io-client';
import { setSearchResult } from 'App/redux/modules/search/actions';
const socket = io('http://localhost:3000');
const configureSocket = dispatch => {
socket.on('SEARCH_RESULT', data => {
setSearchResult(data.Search)(dispatch);
});
return socket;
};
export const searchRequest = query => {
socket.emit('SEARCH_REQUEST', query);
};
export default configureSocket;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment