Skip to content

Instantly share code, notes, and snippets.

@thosakwe
Last active March 18, 2016 14:31
Show Gist options
  • Save thosakwe/280e808bcc2175b273f1 to your computer and use it in GitHub Desktop.
Save thosakwe/280e808bcc2175b273f1 to your computer and use it in GitHub Desktop.
TypeError: Cannot read property 'service' of undefined
import Feathers from 'feathers';
// ...
let app = Feathers();
app
.use(compress())
.options('*', cors())
.use(cors())
.use(BodyParser.json())
.use(BodyParser.urlencoded({extended: true}))
.configure(Hooks())
.configure(Rest())
.configure(SocketIO())
.configure(Authentication({}));
app.use('/users', MongooseService({
Model: Models.User
}));
const Users = app.service('users');
Users.before({
create: [AppHooks.Users.create(), AuthenticationHooks.hashPassword()],
find: [AuthenticationHooks.verifyToken(), AuthenticationHooks.populateUser()],
get: [AuthenticationHooks.verifyToken(), AuthenticationHooks.populateUser()],
update: [AuthenticationHooks.hashPassword(), AuthenticationHooks.verifyToken(), AuthenticationHooks.populateUser(), AuthenticationHooks.requireAuth(), AppHooks.Users.usersCanOnlyModifyThemselves(Users)],
patch: [AuthenticationHooks.hashPassword(), AuthenticationHooks.verifyToken(), AuthenticationHooks.populateUser(), AuthenticationHooks.requireAuth(), AppHooks.Users.usersCanOnlyModifyThemselves(Users)],
remove: [AuthenticationHooks.verifyToken(), AuthenticationHooks.populateUser(), AuthenticationHooks.requireAuth(), AppHooks.Users.usersCanOnlyModifyThemselves(Users)]
}).after({
all: [MongooseService.hooks.toObject(), AppHooks.Users.hidePassword]
});
// ...
export default app;
#!/usr/bin/env node
// ../build/app is my Babel output dir
var app = require('../build/app');
var port = normalizePort(process.env.PORT || '3000');
app.listen(port);
console.log(`Listening on ${port}`);
function normalizePort(val) {
var port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment