Created
April 13, 2016 15:49
-
-
Save cianclarke/660f4af7cba84dad3593121e46350e10 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var mbaasApi = require('fh-mbaas-api'); | |
var express = require('express'); | |
var mbaasExpress = mbaasApi.mbaasExpress(); | |
var cors = require('cors'); | |
// list the endpoints which you want to make securable here | |
var securableEndpoints; | |
securableEndpoints = ['/hello']; | |
var app = express(); | |
// Enable CORS for all requests | |
app.use(cors()); | |
// Note: the order which we add middleware to Express here is important! | |
app.use('/sys', mbaasExpress.sys(securableEndpoints)); | |
app.use('/mbaas', mbaasExpress.mbaas); | |
// allow serving of static files from the public directory | |
app.use(express.static(__dirname + '/public')); | |
// Note: important that this is added just before your own Routes | |
app.use(mbaasExpress.fhmiddleware()); | |
app.use('/hello', require('./lib/hello.js')()); | |
app.get('/fd', function(req, res){ | |
var fs = require('fs'); | |
fs.readdir('/proc/self/fd', function(err, list) { | |
if (err) { | |
return res.status(500).json(err); | |
} | |
return res.end(list.length.toString()); | |
}); | |
}); | |
var MongoClient = require('mongodb').MongoClient; | |
// Connect to the db | |
MongoClient.connect(process.env.FH_MONGODB_CONN_URL, function(err, db) { | |
if(err) { return console.dir(err); } | |
console.log('db connected ok'); | |
}); | |
// Important that this is last! | |
app.use(mbaasExpress.errorHandler()); | |
var port = process.env.FH_PORT || process.env.OPENSHIFT_NODEJS_PORT || 8001; | |
var host = process.env.OPENSHIFT_NODEJS_IP || '0.0.0.0'; | |
app.listen(port, host, function() { | |
console.log("App started at: " + new Date() + " on port: " + port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment