-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
85 lines (68 loc) · 2.11 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* Module dependencies.
*/
var feathers = require('feathers');
var routes = require('./routes');
var user = require('./routes/user');
var http = require('http');
var path = require('path');
var mongoose = require('mongoose');
// Connect to Mongo
var connection = mongoose.connect('mongodb://localhost/test');
// Setup Feathers
var app = feathers();
// all environments
app.set('port', process.env.PORT || 3030);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(feathers.favicon());
app.use(feathers.logger('dev'));
app.use(feathers.json());
app.use(feathers.urlencoded());
app.use(feathers.methodOverride());
app.use(app.router);
app.use(feathers.static(path.join(__dirname, 'public')));
app.use(feathers.static(path.join(__dirname, 'bower_components')));
app.configure(feathers.socketio(function(io) {
io.on('connection', function(socket) {
// Examples
// - Emitting
socket.emit('news', { hello: 'world' });
// - Receiving
socket.on('my other event', function (data) {
console.log(data);
});
});
// Authentication
io.set('authorization', function (handshakeData, callback) {
// Authorize using the /users service
app.lookup('/api/users').find({
username: handshakeData.username,
password: handshakeData.password
}, callback);
});
}));
// development only
if ('development' == app.get('env')) {
app.use(feathers.errorHandler());
}
// Routes
app.get('/', routes.index);
app.get('/users', user.list);
// Views
app.get('/home', function(req,res) {
res.render('home');
});
app.get('/projects', function(req,res) {
res.render('projects');
});
// Feathers Services
var ProjectsService = require(path.join(__dirname, 'services/', 'projects.js'))(connection);
var UsersService = require(path.join(__dirname, 'services/', 'users.js'))(connection);
app.configure(feathers.socketio())
.use(feathers.static(__dirname))
.use('/api/projects', new ProjectsService())
.use('/api/users', new UsersService())
.listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'));
});