mirror of
https://github.com/zhigang1992/deployd.git
synced 2026-05-22 20:37:59 +08:00
settings key fixes
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"port": 3000,
|
||||
"db-host": "mongodb://localhost/",
|
||||
"db-host": "localhost",
|
||||
"db": "deployd"
|
||||
}
|
||||
20
lib/app.js
20
lib/app.js
@@ -1,5 +1,7 @@
|
||||
var express = require('express')
|
||||
, app = express.createServer()
|
||||
, db = require('./db').db
|
||||
, mongoStore = require('connect-mongodb');
|
||||
;
|
||||
|
||||
// expose the app as a module so everyone can use it
|
||||
@@ -19,6 +21,7 @@ app.configure(function(){
|
||||
if (method) {
|
||||
req.method = method.toUpperCase();
|
||||
if(req.body && key in req.body) delete req.body[key];
|
||||
if(req.query && key in req.query) delete req.query[key];
|
||||
// check X-HTTP-Method-Override
|
||||
} else if (req.headers['x-http-method-override']) {
|
||||
req.method = req.headers['x-http-method-override'].toUpperCase();
|
||||
@@ -27,7 +30,12 @@ app.configure(function(){
|
||||
next();
|
||||
});
|
||||
app.use(express.cookieParser());
|
||||
app.use(express.session({ secret: 'your secret here', key: 'deployd.sid', cookie: {httpOnly: false} }));
|
||||
app.use(express.session({
|
||||
secret: 'secret',
|
||||
key: 'deployd.sid',
|
||||
cookie: {httpOnly: false},
|
||||
store: new mongoStore({db: db})
|
||||
}));
|
||||
app.use(app.router);
|
||||
app.use(express.static(__dirname + '/../public'));
|
||||
});
|
||||
@@ -55,4 +63,12 @@ app.get('/routes', function(req, res) {
|
||||
|
||||
app.get('/', function(req, res) {
|
||||
res.send({home: true});
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/dashboard', function(req, res, next) {
|
||||
if(req.session && req.session.user && req.session.user.groups.root) {
|
||||
next();
|
||||
} else {
|
||||
res.send('Not Allowed.')
|
||||
}
|
||||
});
|
||||
|
||||
22
lib/db.js
22
lib/db.js
@@ -2,23 +2,27 @@ var config = require('./config').load()
|
||||
, mongodb = require('mongodb')
|
||||
, ObjectID = require('mongodb').BSONPure.ObjectID
|
||||
, connectionString = config['db-host'] + config['db']
|
||||
, db
|
||||
, Db = mongodb.Db
|
||||
, Server = mongodb.Server
|
||||
, server_config = new Server(config['db-host'], 27017, {auto_reconnect: true, native_parser: true})
|
||||
, db = new Db(config['db'], server_config, {})
|
||||
;
|
||||
|
||||
|
||||
function ready(fn) {
|
||||
return function() {
|
||||
var _self = this
|
||||
, args = arguments
|
||||
;
|
||||
|
||||
db
|
||||
server_config.connected
|
||||
? fn.apply(this, arguments)
|
||||
: mongodb.connect(connectionString, function(err, _db) {
|
||||
if(err || !_db) throw 'Could not connect to' + connectionString + ' (' + err + ')';
|
||||
db = _db;
|
||||
: server_config.connect(db, function(err) {
|
||||
if(err) console.log(err);
|
||||
else {
|
||||
fn.apply(_self, args);
|
||||
})
|
||||
;
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +32,8 @@ function collection(db, model, fn) {
|
||||
|
||||
module.exports = {
|
||||
|
||||
db: db,
|
||||
|
||||
find: ready(function(model) {
|
||||
var query = model.toQuery() || {}
|
||||
, id = model.get('_id') || (query && query._id)
|
||||
@@ -52,11 +58,13 @@ module.exports = {
|
||||
, id = model.get('_id')
|
||||
, _id = id && ObjectID(id)
|
||||
, callback = function(err, result) {
|
||||
if(err) model.error(err.message, err.name);
|
||||
model.refresh(changes);
|
||||
}
|
||||
;
|
||||
|
||||
if(_id && query) query._id = _id;
|
||||
if(_id) changes._id = _id;
|
||||
|
||||
collection(db, model, function(err, collection) {
|
||||
if(query) {
|
||||
|
||||
45
lib/model.js
45
lib/model.js
@@ -343,6 +343,12 @@ Model = module.exports = emitter.spawn({
|
||||
return this;
|
||||
},
|
||||
|
||||
clean: function() {
|
||||
delete this.errors;
|
||||
this.attributes = {};
|
||||
return this;
|
||||
},
|
||||
|
||||
unlock: function() {
|
||||
// allow anyone to edit this specific model
|
||||
// this might be removed from the final API
|
||||
@@ -364,25 +370,51 @@ Model = module.exports = emitter.spawn({
|
||||
settings
|
||||
.find({collection: this.collection, plugin: this.plugin})
|
||||
.set({
|
||||
description: this.description,
|
||||
// description: this.description,
|
||||
plugin: this.plugin,
|
||||
collection: this.collection,
|
||||
name: this.name || this.collection,
|
||||
allowed: this.allowed
|
||||
name: this.name || this.collection
|
||||
// allowed: this.allowed
|
||||
})
|
||||
.notify(function(json) {
|
||||
if(json) {
|
||||
// not found
|
||||
if(json.errors) {
|
||||
json = {
|
||||
plugin: _self.plugin,
|
||||
collection: _self.collection,
|
||||
name: _self.name || _self.collection
|
||||
};
|
||||
}
|
||||
|
||||
delete json._id;
|
||||
_self.description = _self.description || {};
|
||||
_self.description.extend(json.description);
|
||||
|
||||
_self.allowed = _self.allowed || {};
|
||||
|
||||
// default to the models description
|
||||
if(!json.description) json.description = _self.description;
|
||||
// inherit existing description
|
||||
else _self.description.extend(json.description);
|
||||
|
||||
// default to the models allowed
|
||||
if(!json.allowed) json.allowed = _self.allowed;
|
||||
// inherit existing allowed
|
||||
else _self.allowed.extend(json.allowed);
|
||||
|
||||
// save updates
|
||||
this
|
||||
.clean()
|
||||
.find({plugin: json.plugin, collection: json.collection})
|
||||
.set(json)
|
||||
.save();
|
||||
|
||||
// update any special properties
|
||||
_self.configure(_self.description, function(err) {
|
||||
if(err) console.error(err);
|
||||
});
|
||||
}
|
||||
})
|
||||
.save()
|
||||
.fetch()
|
||||
;
|
||||
}
|
||||
|
||||
@@ -421,7 +453,6 @@ Model = module.exports = emitter.spawn({
|
||||
;
|
||||
|
||||
if(id && id.length < 24) return next();
|
||||
|
||||
if(id && !query._id) query._id = id;
|
||||
|
||||
model
|
||||
|
||||
@@ -47,6 +47,10 @@ module.exports = Model.spawn({
|
||||
return app.toLowerCase();
|
||||
},
|
||||
|
||||
defineRoutes: function() {
|
||||
// TODO move routes here
|
||||
},
|
||||
|
||||
toDatabaseName: function() {
|
||||
return this.toHostName().replace(/\./g, ':').toLowerCase();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
var app = require('../../app')
|
||||
, App = require('./app')
|
||||
, Apps = require('./apps')
|
||||
, Invite = require('./invite')
|
||||
;
|
||||
|
||||
@@ -7,7 +8,7 @@ if(process.argv.length < 3) {
|
||||
require('./balancer');
|
||||
}
|
||||
|
||||
app.post('/app', function(req, res) {
|
||||
app.post('/apps', function(req, res) {
|
||||
var session = req.session
|
||||
, me = session && session.user && session.user.email
|
||||
, secret = req.param('secret')
|
||||
@@ -35,17 +36,7 @@ app.post('/app', function(req, res) {
|
||||
|
||||
});
|
||||
|
||||
app.get('/app/:id', function(req, res) {
|
||||
App
|
||||
.spawn()
|
||||
.for(req)
|
||||
.set({_id: req.param('id')})
|
||||
.notify(res)
|
||||
.fetch()
|
||||
;
|
||||
});
|
||||
|
||||
app.del('/app/:id', function(req, res) {
|
||||
app.del('/apps/:id', function(req, res) {
|
||||
App
|
||||
.spawn()
|
||||
.for(req)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
var Settings = require('../settings/settings')
|
||||
, Setting = require('../settings/setting')
|
||||
, Model = require('../../model')
|
||||
, types = require('../../types').validators
|
||||
, app = require('../../app')
|
||||
;
|
||||
|
||||
var models = module.exports.models = {};
|
||||
@@ -19,6 +21,10 @@ var refresh = module.exports.refresh = function() {
|
||||
;
|
||||
}
|
||||
|
||||
app.get('/types', function(req, res) {
|
||||
res.send(Object.keys(types));
|
||||
});
|
||||
|
||||
// initial refresh
|
||||
refresh();
|
||||
|
||||
@@ -29,9 +35,6 @@ Setting
|
||||
.set({
|
||||
plugin: 'models'
|
||||
})
|
||||
.notify(function(json) {
|
||||
console.log(json);
|
||||
})
|
||||
.save()
|
||||
;
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ module.exports = Model.spawn({
|
||||
auth: 'string',
|
||||
removed: 'boolean',
|
||||
groups: 'object'
|
||||
},
|
||||
},
|
||||
|
||||
allowed: {
|
||||
read: 'public',
|
||||
|
||||
@@ -52,6 +52,8 @@ var validators = {
|
||||
|
||||
};
|
||||
|
||||
exports.validators = validators;
|
||||
|
||||
// source can be a String, a validator Function(val), or an Object with a 'type'
|
||||
exports.compile = function(source) {
|
||||
var sourceType = typeof source
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
"underscore": ">= 1.0.0",
|
||||
"mongodb": ">= 0.9.0",
|
||||
"bouncy": ">= 1.0.2",
|
||||
"ejs": ">= 0.4.3"
|
||||
"ejs": ">= 0.4.3",
|
||||
"connect-mongodb": ">= 1.0.0"
|
||||
},
|
||||
"bin":{
|
||||
"deployd":"./bin/deployd"
|
||||
|
||||
@@ -75,7 +75,7 @@ var tests = {
|
||||
},
|
||||
|
||||
'7. creating an app': {
|
||||
route: '/app',
|
||||
route: '/apps',
|
||||
data: app,
|
||||
expect: {
|
||||
_id: 'toExist',
|
||||
|
||||
Reference in New Issue
Block a user