Permalink
Browse files

Fixes for buckets as an NPM module

* Wrap in an index.js for people without coffeescript
* Nixes the "buckets:" key for config, brings everything up (easier to merge)
* Convert 'buckets' module to simply return app for now (for grunt express, will nix soon I think)
  • Loading branch information...
davidkaneda committed Aug 30, 2014
1 parent 9a5a5c7 commit fa100886883a5baa991931b4a336d7a04240c506
View
@@ -151,7 +151,6 @@ module.exports = (grunt) ->
options:
background: false
options:
# port: process.env.PORT or 3000
script: 'server/start.coffee'
opts: ['node_modules/coffee-script/bin/coffee']
View
@@ -0,0 +1,2 @@
require('coffee-script/register');
module.exports = require('./server');
View
@@ -7,7 +7,7 @@
"test": "grunt test",
"test-cov": "grunt test:server:cov"
},
"main": "server/index.coffee",
"main": "index.js",
"config": {
"blanket": {
"loader": "./node-loaders/coffee-script",
View
@@ -3,17 +3,16 @@ _ = require 'underscore'
config =
default:
buckets:
adminSegment: 'admin'
apiSegment: 'api'
salt: 'BUCKETS4LIFE!!1'
port: process.env.PORT || 3000
env: env
templatePath: "#{__dirname}/../user/templates/"
publicPath: "#{__dirname}/../user/public/"
pluginsPath: "#{__dirname}/../node_modules/"
catchAll: yes
autoStart: yes
adminSegment: 'admin'
apiSegment: 'api'
salt: 'BUCKETS4LIFE!!1'
port: process.env.PORT || 3000
env: env
templatePath: "#{__dirname}/../user/templates/"
publicPath: "#{__dirname}/../user/public/"
pluginsPath: "#{__dirname}/../node_modules/"
catchAll: yes
autoStart: yes
db: "mongodb://localhost/buckets_#{env}"
production:
smtp:
View
@@ -1,53 +1,57 @@
_ = require 'underscore'
express = require 'express'
cookieParser = require 'cookie-parser'
bodyParser = require 'body-parser'
session = require 'cookie-session'
compression = require 'compression'
colors = require 'colors'
class Buckets
constructor: (config) ->
_ = require 'underscore'
baseConfig = require './config'
passport = require './lib/auth'
baseConfig = require './config'
@config = baseConfig = _.extend baseConfig, config
class Buckets
routers:
admin: require './routes/admin'
api: require './routes/api'
frontend: require './routes/frontend'
express = require 'express'
cookieParser = require 'cookie-parser'
bodyParser = require 'body-parser'
session = require 'cookie-session'
compression = require 'compression'
colors = require 'colors'
constructor: ->
@app = express()
passport = require './lib/auth'
init: (config={}) ->
@config = _.extend baseConfig, config
@routers =
admin: require './routes/admin'
api: require './routes/api'
frontend: require './routes/frontend'
@app = express()
# Handle cookies and sessions and stuff
@app.use compression()
@app.use cookieParser @config.buckets.salt
@app.use cookieParser @config.salt
@app.use session
secret: @config.buckets.salt
secret: @config.salt
name: 'buckets'
@app.use bodyParser.json()
@app.use bodyParser.urlencoded extended: true
@app.use passport.initialize()
@app.use passport.session()
# Load Routes for the API, admin, and frontend
@app.use "/#{@config.buckets.apiSegment}", @routers.api
@app.use "/#{@config.buckets.adminSegment}", @routers.admin
@app.use @routers.frontend
@app.set 'view engine', 'hbs'
@start() if @config.buckets.autoStart
# Load Routes for the API, admin, and frontend
@app.use "/#{@config.apiSegment}", @routers.api
@app.use "/#{@config.adminSegment}", @routers.admin
@app.use @routers.frontend
@
@start() if @config.autoStart
start: (done) ->
done?() if @server
@server ?= @app.listen @config.buckets.port, =>
console.log ("\nBuckets is running at " + "http://localhost:#{@config.buckets.port}/".underline.bold).yellow
@server ?= @app.listen @config.port, =>
console.log ("\nBuckets is running at " + "http://localhost:#{@config.port}/".underline.bold).yellow
done?()
module.exports = new Buckets
stop: (done) ->
done?() unless @server
@server.close done
# There can be only one #highlander
buckets = null
module.exports = (config={}) ->
buckets ?= new Buckets config
@@ -8,7 +8,7 @@ hbs = require 'hbs'
db = require '../lib/database'
config = require '../config'
cwd = config.buckets?.pluginsPath
cwd = config?.pluginsPath
module.exports =
load: ->
@@ -10,7 +10,7 @@ module.exports = (hbs) ->
# Add Swag helpers
Swag.registerHelpers hbs.handlebars
hbs.registerPartials config.buckets.templatePath
hbs.registerPartials config.templatePath
# formatTime helper
hbs.registerHelper 'formatTime', (value, options) ->
@@ -13,7 +13,7 @@ User = require '../models/user'
module.exports = app = express()
{adminSegment} = config.buckets
{adminSegment} = config
hbs.registerHelper 'json', (context) ->
new hbs.handlebars.SafeString JSON.stringify(context)
@@ -64,8 +64,8 @@ app.all '*', (req, res) ->
res.render 'admin',
user: req.user
env: config.buckets.env
env: config.env
plugins: localPlugins
adminSegment: adminSegment
apiSegment: config.buckets.apiSegment
apiSegment: config.apiSegment
needsInstall: userCount is 0
@@ -2,7 +2,7 @@ express = require 'express'
hbs = require 'hbs'
config = require '../../config'
Template = require('../../lib/template')(config.buckets?.templatePath)
Template = require('../../lib/template')(config?.templatePath)
module.exports = app = express()
@@ -202,7 +202,7 @@ app.post '/forgot', (req, res) ->
text: """
You are receiving this because you (or someone else) has requested the reset of the password for your account.\n
Please click on the following link, or paste this into your browser to complete the process:\n
http://#{req.headers.host}/#{config.buckets.adminSegment}/reset/#{token}\n\n
http://#{req.headers.host}/#{config.adminSegment}/reset/#{token}\n\n
If you did not request this, please ignore this email and your password will remain unchanged.\n
"""
mailer.sendMail mailOptions, (err) ->
@@ -10,14 +10,14 @@ config = require '../config'
Route = require '../models/route'
module.exports = app = express()
tplPath = config.buckets?.templatePath
tplPath = config.templatePath
require('../lib/renderer')(hbs)
app.set 'views', tplPath
app.set 'view cache', off
app.use express.static config.buckets.publicPath, maxAge: 86400000 * 7 # One week
app.use express.static config.publicPath, maxAge: 86400000 * 7 # One week
plugins = app.get 'plugins'
@@ -34,7 +34,7 @@ app.get '*', (req, res, next) ->
# Prepare the global template data
templateData =
adminSegment: config.buckets.adminSegment
adminSegment: config.adminSegment
req:
body: req.body
path: req.path
View
@@ -1 +1 @@
require('./../server/index').init().start()
require('./../server')()
View
@@ -1,6 +1,6 @@
db = require '../server/lib/database'
config = require '../server/config'
buckets = require('../server').init()
buckets = require('../server')
Entry = require '../server/models/entry'
dropDatabase = (done) ->
@@ -15,7 +15,7 @@ prep = (done) ->
db.connection.db.dropDatabase done
server = (done) ->
buckets.init().start done
buckets().start done
module.exports =
db: dropDatabase
@@ -22,7 +22,7 @@ describe 'Install routes', ->
it 'returns an error if password isn’t valid', (done) ->
request app
.post "/#{config.buckets.apiSegment}/install"
.post "/#{config.apiSegment}/install"
.send
name: 'Test User'
email: 'user@buckets.io'
@@ -40,7 +40,7 @@ describe 'Install routes', ->
describe 'Installation', ->
it 'should return a populated user object w/administrator permissions', (done) ->
request app
.post "/#{config.buckets.apiSegment}/install"
.post "/#{config.apiSegment}/install"
.send
name: 'Test User'
email: 'user@buckets.io'
@@ -4,7 +4,7 @@ config = require "#{serverPath}/config"
User = require "#{serverPath}/models/user"
reset = require '../../reset'
buckets = require(serverPath).init()
buckets = require(serverPath)()
request = require 'supertest'
@@ -26,7 +26,7 @@ describe 'Auth routes', ->
describe 'POST /login', (done) ->
it 'logs in with correct credentials and redirects to /admin/', (done) ->
request app
.post "/#{config.buckets.adminSegment}/login"
.post "/#{config.adminSegment}/login"
.send
username: 'test+admin@buckets.io'
password: 'testing123'
@@ -38,7 +38,7 @@ describe 'Auth routes', ->
it 'redirects to /admin/login with incorrect credentials', (done) ->
request app
.post "/#{config.buckets.adminSegment}/login"
.post "/#{config.adminSegment}/login"
.send
username: 'test+admin@buckets.io'
password: 'testing456'
@@ -51,7 +51,7 @@ describe 'Auth routes', ->
describe 'POST /checkLogin (AJAX-based login check)', ->
it 'returns a 200 if authentication succeeds', (done) ->
request app
.post "/#{config.buckets.adminSegment}/checkLogin"
.post "/#{config.adminSegment}/checkLogin"
.send
username: 'test+admin@buckets.io'
password: 'testing123'
@@ -60,7 +60,7 @@ describe 'Auth routes', ->
it 'returns a 401 (with errors) if authentication fails', (done) ->
request app
.post "/#{config.buckets.adminSegment}/checkLogin"
.post "/#{config.adminSegment}/checkLogin"
.send
username: 'test+admin@buckets.io'
password: 'testing456'

0 comments on commit fa10088

Please sign in to comment.