Skip to content

Instantly share code, notes, and snippets.

@juodumas
Last active April 14, 2016 15:30
Show Gist options
  • Save juodumas/8ac8702a0279168cf92f8ff966c5643b to your computer and use it in GitHub Desktop.
Save juodumas/8ac8702a0279168cf92f8ff966c5643b to your computer and use it in GitHub Desktop.
Feathers doesn't report any error when accessing non existent services over sockets
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script src="socket.io.js"></script>
<script src="//cdn.rawgit.com/feathersjs/feathers-client/v1.1.0/dist/feathers.js"></script>
<script>
function feathersTransportTest(transport) {
var app = feathers()
app.configure(feathers.hooks())
if (transport == 'REST') {
app.configure(feathers.rest().fetch(window.fetch.bind(window)))
}
// Then try WebSockets.
else {
var socket = io()
app.configure(feathers.socketio(socket))
}
var userService = app.service('users')
var nonexistentService = app.service('nonexistent')
userService.find()
.then(function(r) { console.log(`${transport}:users:ok`, r) })
.catch(function(r) { console.log(`${transport}:users:error`, r) })
nonexistentService.find()
.then(function(r) { console.log(`${transport}:nonexistent:ok`, r) })
.catch(function(r) { console.log(`${transport}:nonexistent:error`, r) })
}
feathersTransportTest('REST')
feathersTransportTest('WS')
</script>
</body>
</html>
// npm init --yes
// npm i feathers feathers-memory feathers-socketio feathers-hooks feathers-rest feathers-socketio body-parser
const bodyParser = require('body-parser')
const feathers = require('feathers')
const hooks = require('feathers-hooks')
const rest = require('feathers-rest')
const socketio = require('feathers-socketio')
const memory = require('feathers-memory')
const app = feathers()
.configure(rest())
.configure(socketio())
.configure(hooks())
.use(bodyParser.json())
.use(bodyParser.urlencoded({extended: true}))
.use(feathers.static(__dirname + '/public'))
app.use('users', memory())
app.service('users').create({
id: 'admin',
email: 'admin@localhost',
password: 'admin'
})
.then(function(r) { console.log("created admin", r) })
.catch(function(r) { console.log("error creating admin", r) })
app.listen(3030)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment