Skip to content

Commit

Permalink
Merge pull request #78 from BadCityGame/resurrect
Browse files Browse the repository at this point in the history
Confirmed working by @parkerlreed so I'm merging. So excited to have progress on this!
  • Loading branch information
jareiko committed Feb 26, 2019
2 parents fd01d88 + 4ce3323 commit 3b96ec5
Show file tree
Hide file tree
Showing 50 changed files with 4,402 additions and 521 deletions.
6 changes: 6 additions & 0 deletions .gitignore
@@ -0,0 +1,6 @@
node_modules/
closure-compiler/
# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
Expand Down
10 changes: 10 additions & 0 deletions README.md
Expand Up @@ -22,3 +22,13 @@ Copyright & License
Copyright (c) 2012-2013 [Code Artemis](https://github.com/CodeArtemis) unless otherwise attributed.

See [LICENSE.md](LICENSE.md).

To Run
-------------------

Install MongoDB

cd server
npm i
npm i -g coffee-script
npm start
3 changes: 2 additions & 1 deletion server/api.coffee
Expand Up @@ -14,7 +14,8 @@ findModel = (Model, pub_id, done) ->
model = Model.findOrCreate pub_id
result = model.fetch
success: -> done model
error: -> done null
error:(e1, e2) ->
console.error('Error when loading model', pub_id)
done null if result is false

findCar = -> findModel(bb.Car, arguments...)
Expand Down
85 changes: 50 additions & 35 deletions server/app.coffee
@@ -1,10 +1,16 @@
"use strict"

_ = require 'underscore'
bodyParser = require 'body-parser'
cookieParser = require 'cookie-parser'
connect = require 'connect'
compression = require 'compression'
cookie = require 'cookie'
express = require 'express'
expressSession = require 'express-session'
http = require 'http'
logger = require 'morgan'
methodOverride = require 'method-override'
mongoose = require 'mongoose'
mongoskin = require 'mongoskin'
session_mongoose = require 'session-mongoose'
Expand All @@ -24,14 +30,16 @@ config = require './config'
{ makePubId } = require './objects/common'
routes = require './routes'

stripe = require('stripe')(config.stripe.API_KEY)
# stripe = require('stripe')(config.stripe.API_KEY)

getIsodate = -> new Date().toISOString()
express.logger.format 'isodate', (req, res) -> getIsodate()
logger.format 'isodate', (req, res) -> getIsodate()
log = (msg) ->
isodate = getIsodate()
console.log "[#{isodate}] #{msg}"

mongoose.set 'debug', true

mongoose.connection.on "error", (err) ->
log "Could not connect to mongo server!"
log err.message
Expand Down Expand Up @@ -115,31 +123,31 @@ authenticationSuccessful = (req, res) ->
# done null, user
#)

for i in ["", "/v1"]
passport.use "facebook#{i}", new FacebookStrategy(
clientID: config.FACEBOOK_APP_ID
clientSecret: config.FACEBOOK_APP_SECRET
callbackURL: "#{URL_PREFIX}#{i}/auth/facebook/callback"
, (accessToken, refreshToken, profile, done) ->
profile.auth = { accessToken, refreshToken }
authenticateUser profile, done
)
passport.use "google#{i}", new GoogleStrategy(
clientID: config.GOOGLE_CLIENT_ID
clientSecret: config.GOOGLE_CLIENT_SECRET
callbackURL: "#{URL_PREFIX}#{i}/auth/google/callback"
, (token, refreshToken, profile, done) ->
profile.auth = { token, refreshToken }
authenticateUser profile, done
)
passport.use "twitter#{i}", new TwitterStrategy(
consumerKey: config.TWITTER_APP_KEY
consumerSecret: config.TWITTER_APP_SECRET
callbackURL: "#{URL_PREFIX}#{i}/auth/twitter/callback"
, (token, tokenSecret, profile, done) ->
profile.auth = { token, tokenSecret }
authenticateUser profile, done
)
# for i in ["", "/v1"]
# passport.use "facebook#{i}", new FacebookStrategy(
# clientID: config.FACEBOOK_APP_ID
# clientSecret: config.FACEBOOK_APP_SECRET
# callbackURL: "#{URL_PREFIX}#{i}/auth/facebook/callback"
# , (accessToken, refreshToken, profile, done) ->
# profile.auth = { accessToken, refreshToken }
# authenticateUser profile, done
# )
# passport.use "google#{i}", new GoogleStrategy(
# clientID: config.GOOGLE_CLIENT_ID
# clientSecret: config.GOOGLE_CLIENT_SECRET
# callbackURL: "#{URL_PREFIX}#{i}/auth/google/callback"
# , (token, refreshToken, profile, done) ->
# profile.auth = { token, refreshToken }
# authenticateUser profile, done
# )
# passport.use "twitter#{i}", new TwitterStrategy(
# consumerKey: config.TWITTER_APP_KEY
# consumerSecret: config.TWITTER_APP_SECRET
# callbackURL: "#{URL_PREFIX}#{i}/auth/twitter/callback"
# , (token, tokenSecret, profile, done) ->
# profile.auth = { token, tokenSecret }
# authenticateUser profile, done
# )

passport.serializeUser (userPassport, done) ->
done null, userPassport.id
Expand All @@ -151,9 +159,9 @@ passport.deserializeUser (id, done) ->
.exec (error, userPassport) ->
done error, userPassport

app.use express.logger(format: '[:isodate] :status :response-time ms :res[content-length] :method :url :referrer')
app.use logger('[:isodate] :status :response-time ms :res[content-length] :method :url :referrer', format: '[:isodate] :status :response-time ms :res[content-length] :method :url :referrer')
app.disable 'x-powered-by'
app.use express.compress()
app.use compression()
app.use stylus.middleware(
src: __dirname + '/stylus'
dest: __dirname + '/public'
Expand All @@ -166,17 +174,24 @@ app.use (req, res, next) ->
# req.setEncoding('utf8')
req.on 'data', (chunk) -> req.rawBody += chunk
next()
app.use express.bodyParser()
app.use express.cookieParser(config.SESSION_SECRET)
app.use express.session(
app.use bodyParser.urlencoded({
extended: true
})
app.use bodyParser.json();

app.use cookieParser(config.SESSION_SECRET)
app.use expressSession(
secret: 'asecret'
saveUninitialized: true
resave: true
cookie:
maxAge: 4 * 7 * 24 * 60 * 60 * 1000

store: sessionStore
)
app.use passport.initialize()
app.use passport.session()
app.use express.methodOverride()
app.use methodOverride()
app.use (req, res, next) ->
# Enable Chrome Frame if installed.
res.setHeader 'X-UA-Compatible', 'chrome=1'
Expand All @@ -201,14 +216,14 @@ app.use app.router
# TODO: Make the app show a 404 as appropriate.
app.use routes.unified

app.configure 'development', ->
if app.get('env') is 'development'
app.use (err, req, res, next) ->
console.error err
res.json 500,
error: "Internal Server Error"
call_stack: err.stack?.split('\n')

app.configure 'production', ->
if app.get('env') is 'production'
app.use (err, req, res, next) ->
console.error err
res.json 500,
Expand Down
8 changes: 8 additions & 0 deletions server/config.coffee
@@ -0,0 +1,8 @@
module.exports =
MONGODB_HOST: 'mongodb://localhost:27017/triggered'
MONGOOSE_URL: 'mongodb://localhost:27017/triggered'
SESSION_SECRET: 'big_secret'
db:
host: 'localhost'
port: 27017
name: 'triggered'

1 comment on commit 3b96ec5

@parkerlreed
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6595q

Please sign in to comment.