oauth
This commit is contained in:
parent
a8731fa204
commit
80ecdc565c
3
app.js
3
app.js
@ -25,4 +25,5 @@ var env = require(__dirname + '/config/environments/' + ENV)
|
||||
_.extend(global.settings, env);
|
||||
|
||||
// kick off controller
|
||||
require(global.settings.app_root + '/app/controllers/app');
|
||||
var app = require(global.settings.app_root + '/app/controllers/app');
|
||||
app.listen(global.settings.node_port);
|
@ -1,4 +1,8 @@
|
||||
var app = require('express').createServer()
|
||||
var express= require('express')
|
||||
, app = express.createServer(
|
||||
//TODO: make logs async background + 1min or so
|
||||
//express.logger('\033[90m:method\033[0m \033[36m:url\033[0m \033[90m:status :response-timems -> :res[Content-Type]\033[0m')
|
||||
)
|
||||
, Step = require(global.settings.app_root + '/lib/step')
|
||||
, oAuth = require(global.settings.app_root + '/app/models/oauth')
|
||||
, PSQL = require(global.settings.app_root + '/app/models/psql')
|
||||
@ -45,7 +49,6 @@ app.get('/v1/', function(req, res){
|
||||
},
|
||||
function packageResults(err, result){
|
||||
if (err) throw err;
|
||||
//pg.end(); //TODO: Fix this - we should use a proper generic pool
|
||||
res.send(result.rows);
|
||||
},
|
||||
function exceptionHandle(err, result){
|
||||
@ -62,5 +65,7 @@ function handleException(res, err){
|
||||
res.send(msg, 400);
|
||||
}
|
||||
|
||||
app.listen(global.settings.node_port);
|
||||
//module.exports = app;
|
||||
//app.listen(global.settings.node_port);
|
||||
|
||||
// Think of putting it behind a cluster in production
|
||||
module.exports = app;
|
||||
|
49
cluster.js
49
cluster.js
@ -1,13 +1,36 @@
|
||||
// #! /Users/fernando/local/node/bin/node
|
||||
//
|
||||
// var cluster = require('cluster');
|
||||
//
|
||||
// cluster('./app')
|
||||
// .use(cluster.logger('logs'))
|
||||
// .set('workers', 2)
|
||||
// .use(cluster.stats())
|
||||
// .use(cluster.pidfiles('pids'))
|
||||
// .use(cluster.cli())
|
||||
// .use(cluster.repl(8888))
|
||||
// .use(cluster.debug())
|
||||
// .listen(3000);
|
||||
#!/usr/bin/env node
|
||||
|
||||
/*
|
||||
* SQL API loader
|
||||
* ===============
|
||||
*
|
||||
* node app [environment]
|
||||
*
|
||||
* environments: [development, test, production]
|
||||
*
|
||||
*/
|
||||
var _ = require('underscore');
|
||||
var cluster = require('cluster');
|
||||
|
||||
// sanity check arguments
|
||||
var ENV = process.argv[2]
|
||||
if (ENV != 'development' && ENV != 'production') {
|
||||
console.error("\nnode app [environment]");
|
||||
console.error("environments: [development, test, production]");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// set Node.js app settings and boot
|
||||
global.settings = require(__dirname + '/config/settings')
|
||||
var env = require(__dirname + '/config/environments/' + ENV)
|
||||
_.extend(global.settings, env);
|
||||
|
||||
cluster('./app/controllers/app')
|
||||
.use(cluster.logger('logs'))
|
||||
.set('workers', 2)
|
||||
.use(cluster.stats())
|
||||
.use(cluster.pidfiles('pids'))
|
||||
.use(cluster.cli())
|
||||
.use(cluster.repl(8888))
|
||||
.use(cluster.debug())
|
||||
.listen(4000);
|
||||
|
@ -1,5 +1,8 @@
|
||||
require('../helper');
|
||||
|
||||
// Requires the database and tables setup in config/environments/test.js to exist
|
||||
// Ensure the user is present in the pgbouncer auth file too
|
||||
|
||||
var app = require(global.settings.app_root + '/app/controllers/app')
|
||||
, assert = require('assert');
|
||||
|
||||
@ -12,13 +15,30 @@ module.exports = {
|
||||
body: '{"error":["You must indicate a sql query"]}',
|
||||
status: 400
|
||||
});
|
||||
}// ,
|
||||
// 'GET /v1/ with SQL parameter': function(){
|
||||
// assert.response(app, {
|
||||
// url: '/v1/?sql=bla',
|
||||
// method: 'GET'
|
||||
// },{
|
||||
// status: 200
|
||||
// });
|
||||
// }
|
||||
},
|
||||
'GET /v1/ with SQL parameter on SELECT only. No oAuth included ': function(){
|
||||
assert.response(app, {
|
||||
url: '/v1/?sql=SELECT%20*%20FROM%20test_table&database=cartodb_test_user_1_db',
|
||||
method: 'GET'
|
||||
},{
|
||||
status: 200
|
||||
});
|
||||
},
|
||||
'GET /v1/ with SQL parameter on SELECT only. oAuth used ': function(){
|
||||
assert.response(app, {
|
||||
url: '/v1/?sql=SELECT%20*%20FROM%20test_table&oauth_token=1',
|
||||
method: 'GET'
|
||||
},{
|
||||
status: 200
|
||||
});
|
||||
},
|
||||
'GET /v1/ with SQL parameter on INSERT only. oAuth used ': function(){
|
||||
assert.response(app, {
|
||||
url: "/v1/?sql=INSERT%20INTO%20test_table%20(id)%20VALUES%20(1)&oauth_token=1",
|
||||
method: 'GET'
|
||||
},{
|
||||
status: 200
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user