Last active
May 2, 2019 05:39
-
-
Save beardlessman/04bc039efab81daf0601575385aaa331 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
// 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