-
-
Save Upguard/e196b3ea016e8234a86342991ce6db24 to your computer and use it in GitHub Desktop.
Feathers socketio client implementation into vuejs/vuex
This file contains 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
import * as services from './sockets' | |
export const fetchSites = ({ dispatch, state }) => { | |
services.siteService.find({}).then(sites => { | |
dispatch(types.MARKET_SITES, sites.data) | |
}) | |
} |
This file contains 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 side | |
'use strict'; | |
import 'babel-polyfill' | |
const path = require('path'); | |
const serveStatic = require('feathers').static; | |
const favicon = require('serve-favicon'); | |
const compress = require('compression'); | |
const cors = require('cors'); | |
const feathers = require('feathers'); | |
const configuration = require('feathers-configuration'); | |
const hooks = require('feathers-hooks'); | |
const rest = require('feathers-rest'); | |
const bodyParser = require('body-parser'); | |
const socketio = require('feathers-socketio'); | |
const middleware = require('./middleware'); | |
const services = require('./services'); | |
const app = feathers(); | |
app.configure(configuration(path.join(__dirname, '..'))); | |
app.use(compress()) | |
.options('*', cors()) | |
.use(cors()) | |
.use(favicon( path.join(app.get('public'), 'favicon.ico') )) | |
.use('/', serveStatic( app.get('public') )) | |
.use(bodyParser.json()) | |
.use(bodyParser.urlencoded({ extended: true })) | |
.configure(hooks()) | |
.configure(rest()) | |
.configure(socketio()) | |
.configure(services) | |
.configure(middleware); | |
module.exports = app; |
This file contains 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
'use strict' | |
module.exports = { | |
socket: { | |
url: 'https://feathers-upguard.c9users.io' | |
} | |
} |
This file contains 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
<template> | |
<div id="marketplace"> | |
<ul v-for="site in sites"> | |
<li>Site name: {{ site.name }}</li> | |
<li>Description: {{ site.description }}</li> | |
<li>Category: {{ site.category }}</li> | |
<li><img :src="site.screenshot" width="150px"></li> | |
<li>Monthly Uniques: {{ site.estimated_monthly_visitors }}</li> | |
</ul> | |
</div> | |
</template> | |
<script> | |
import { fetchSites } from '../../vuex/actions' | |
import UiButton from 'keen-ui/lib/UiButton' | |
export default { | |
data () { | |
return { | |
// | |
} | |
}, | |
ready () { | |
this.fetchSites() | |
}, | |
vuex: { | |
actions: { | |
fetchSites | |
}, | |
getters: { | |
error: state => state.error, | |
user: state => state.user, | |
sites: state => state.sites | |
} | |
}, | |
components: { | |
UiButton | |
} | |
} | |
</script> |
This file contains 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
// located in sockets/index.js | |
const feathers = require('feathers/client') | |
const socketio = require('feathers-socketio/client') | |
const io = require('socket.io-client') | |
import config from '../config/env' | |
const socket = io(config.socket.url) | |
export const app = feathers().configure(socketio(socket)) | |
export const siteService = app.service('sites') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment