-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
85 lines (74 loc) · 2.63 KB
/
app.js
File metadata and controls
85 lines (74 loc) · 2.63 KB
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
//
// app.js
//
// - Exports an express route including all Jibe components. Also handles
// BrowserChannel for ShareJS; socket.io for chat and timestamps.
//
// Copyright (c) 2015 Visionist, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
module.exports = function(options) {
// check options to see if a config was supplied
if (options && options.config) {
// if it was, want to initialize with the supplied configuration
require('./lib/config')(options.config);
} else {
// otherwise, just use the default
require('./lib/config')();
}
// now that config has been initialized, require the other dependencies
var express = require('express');
var path = require('path');
var chatRoutes = require('./lib/routes/chat.js');
var opsRoutes = require('./lib/routes/ops');
var chatHandler = require('./lib/sockets/chat.js');
var browserChannel = require('./lib/middleware/browserchannel.js');
var shareRoutes = browserChannel.rest;
var router = express.Router();
return {
/**
* This function creates and returns an Express 4 Router.
*
* As a side effect, creates the necessary socket channels using the given
* socketIO object.
*
* Example usage:
*
* var express = require('express'),
* app = express(),
* server = require('http').createServer(app),
* io = require('socket.io').listen(server);
*
* var jibe = require('jibe');
* app.use(jibe(io).router);
* app.use(jibe.browserChannelMiddleware);
*/
router: function(io) {
// chat routes
router.use('/chat', chatRoutes);
// ops routes
router.use('/ops', opsRoutes);
// ShareJS built-in REST routes
router.use('/docs', shareRoutes);
if(io) {
io.of('/chat').on('connection', chatHandler);
}
router.use('/lib', express.static(path.join(__dirname, '/node_modules')));
router.use(express.static(path.join(__dirname, '/public')));
return router;
},
// app.use(jibe.browserChannelMiddleware)
browserChannelMiddleware: browserChannel.middleware
};
};