-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
88f0670
commit bceb19c
Showing
15 changed files
with
330 additions
and
86 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,29 @@ | ||
var bodyParser = require( 'body-parser' ), | ||
var express = require('express'), | ||
bodyParser = require( 'body-parser' ), | ||
session = require( 'express-session' ), | ||
RestResource = require( './rest' ); | ||
|
||
module.exports = function (config, app) { | ||
'use strict'; | ||
var router = express.Router(); | ||
|
||
app.get( config.apiBase + '/plugins', RestResource.plugins ); | ||
app.get( config.apiBase + '/readme', RestResource.readme ); | ||
app.get( config.apiBase, RestResource.index ); | ||
// a middleware with no mount path, gets executed for every request to the router | ||
router.use(function (req, res, next) { | ||
console.log('cms-rest Time:', Date.now()); | ||
next(); | ||
}); | ||
|
||
router.get( config.apiBase, RestResource.index ); | ||
router.get( config.apiBase + '/plugins', RestResource.plugins ); | ||
router.get( config.apiBase + '/readme', RestResource.readme ); | ||
|
||
//Dynamic REST | ||
app.get( config.apiBase + '/:db/:collection/:id?', RestResource.get ) | ||
app.post( config.apiBase + '/:db/:collection/:id?', bodyParser.json(), RestResource.add ) | ||
app.put( config.apiBase + '/:db/:collection/:id?', bodyParser.json(), RestResource.edit ) | ||
app.delete( config.apiBase + '/:db/:collection/:id?', RestResource.destroy ); | ||
router.get( config.apiBase + '/:db/:collection/:id?', RestResource.get ) | ||
router.post( config.apiBase + '/:db/:collection/:id?', bodyParser.json(), RestResource.add ) | ||
router.put( config.apiBase + '/:db/:collection/:id?', bodyParser.json(), RestResource.edit ) | ||
router.delete( config.apiBase + '/:db/:collection/:id?', RestResource.destroy ); | ||
|
||
console.warn( 'cms-rest', 'initialized' ); | ||
|
||
app.use('/', router); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
var mongoose = require('mongoose'); | ||
var mongoose = require('mongoose'), http = require('http'), util = require('util'); | ||
|
||
module.exports.mount = function (config, app) { | ||
'use strict'; | ||
|
||
//Connect to database | ||
mongoose.connect(config.mongodb); | ||
|
||
var server = http.createServer(app); | ||
|
||
require( './cms-auth' )( config, app ); | ||
require( './cms-passport' )( config, app ); | ||
require( './cms-rest' )( config, app ); | ||
require( './cms-proxy' )( config, app ); | ||
require( './cms-sockets' )( config, app ); | ||
require( './cms-server' )( config, app ); | ||
require( './cms-upload' )( config, app ); | ||
require( './cms-sockets' )( config, server ); | ||
require( './cms-server' )( config, app ); | ||
|
||
return server.listen(config.port || process.env.PORT, function () { | ||
util.log('App listening on port: ' + config.port + ''.verbose); | ||
util.log(util.inspect(config, {colors: true})); | ||
}); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,31 @@ | ||
var express = require('express'), | ||
path = require('path'), | ||
bodyParser = require( 'body-parser' ); | ||
|
||
module.exports = function (config, app) { | ||
console.warn( 'cms-server'); | ||
console.warn( 'cms-server initialized'); | ||
|
||
var router = express.Router(); | ||
|
||
var options = { | ||
dotfiles: 'ignore', | ||
etag: false, | ||
extensions: ['htm', 'html'], | ||
index: false, | ||
maxAge: '1d', | ||
redirect: false, | ||
setHeaders: function (res, path) { | ||
res.set('x-timestamp', Date.now()) | ||
} | ||
}; | ||
|
||
router.use(express.static(config.staticDir, options)); | ||
router.use(express.static(config.publicDir, options)); | ||
router.use('/', function(res, req, next){ | ||
req.send(config.publicDir + path.sep + 'index.html'); | ||
next(); | ||
}); | ||
|
||
app.use('/', router); | ||
|
||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,105 @@ | ||
|
||
const events = require('events'), util = require('util'); | ||
|
||
var cmsSockets = function (config, app) { | ||
var q = require( 'q' ), | ||
WebSocketServer = require('websocket').server, | ||
WebSocketRouter = require('websocket').router; | ||
//////////////////////////// | ||
//## Socket Server | ||
//This is a socket server implementation for 'real' time analytics and other data. | ||
//This is for use with geo analytics and other backend data from the app. listen for connected clients | ||
// | ||
// ### Server Channels | ||
//These are the events that this socket server dispatches. | ||
// | ||
//1. cms:authorization | ||
//2. cms:client:message | ||
//3. cms:client:connect | ||
//4. cms:client:disconnect | ||
//5. cms:server:message | ||
//6. cms:server:disconnect | ||
//7. cms:server:connect | ||
//8. cms: | ||
module.exports = function (config, app) { | ||
'use strict'; | ||
events.EventEmitter.call(this); | ||
console.warn( 'cms-sockts initialized' ); | ||
|
||
console.warn( 'cms-sockts' ); | ||
//Start the websocket server | ||
//SocketServer.init(proxyServer); | ||
var cmsSockets = {}, | ||
connections, wsserver, wsclient, router, self = cmsSockets; | ||
|
||
}; | ||
|
||
util.inherits(cmsSockets, events.EventEmitter); | ||
module.exports = cmsSockets; | ||
var delay = function (fn, time) { | ||
var defer = q.defer(); | ||
setTimeout( function () { | ||
fn(); | ||
defer.resolve(); | ||
}, time ); | ||
return defer.promise; | ||
}; | ||
|
||
var delayedSocketPush = function(socket, time){ | ||
return delay( function (msg) { | ||
socket.emit( 'msg', { | ||
datetime: new Date(), | ||
message: msg, | ||
id: 'Server' | ||
} ); | ||
}, time ); | ||
}; | ||
|
||
//Hold the names of events that this socket server listens for and emits | ||
self.events = { | ||
session: { | ||
pageView: 'cms:session:pageView', | ||
hashChange: 'cms:session:hashChange', | ||
login: 'cms:session:login', | ||
logout: 'cms:session:logout' | ||
}, | ||
server: { | ||
message: 'cms:server:message', | ||
connected: 'cms:server:connect', | ||
disconnected: 'cms:server:disconnect' | ||
}, | ||
client: { | ||
message: 'cms:client:message', | ||
connected: 'cms:client:connect', | ||
disconnected: 'cms:client:disconnect' | ||
} | ||
}; | ||
|
||
|
||
//Store a list of the connected clients | ||
connections = []; | ||
|
||
var serverConfig = { | ||
httpServer: app, | ||
}; | ||
|
||
wsserver = new WebSocketServer(); | ||
wsserver.mount(serverConfig); | ||
|
||
router = new WebSocketRouter(); | ||
router.attachServer(wsserver); | ||
|
||
router.mount('*', 'echo-protocol', function(request) { | ||
console.log('mounted to echo protocol'); | ||
var conn = request.accept(request.origin); | ||
conn.on('message', function(message) { | ||
console.log('routed message', message); | ||
}); | ||
conn.send('hey'); | ||
}); | ||
|
||
router.mount('*', 'update-protocol', function(request) { | ||
console.log('mounted to update protocol'); | ||
var conn = request.accept(request.origin); | ||
conn.on('message', function(message) { | ||
console.log('update all the things', message); | ||
}); }); | ||
|
||
util.inherits(cmsSockets, events.EventEmitter); | ||
|
||
}; |
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
Oops, something went wrong.