-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d036794
commit c0b7b92
Showing
5 changed files
with
117 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
option_settings: | ||
- namespace: aws:elasticbeanstalk:container:nodejs:staticfiles | ||
option_name: /public | ||
value: /public | ||
value: /public | ||
- option_name: NODE_ENV | ||
value: production |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,95 @@ | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var express = require('express') | ||
, routes = require('./routes') | ||
, user = require('./routes/user') | ||
, hike = require('./routes/hike') | ||
, http = require('http') | ||
, path = require('path') | ||
, hike = require('./routes/hike'); | ||
, mysql = require('mysql') | ||
, async = require('async'); | ||
|
||
var app = express(); | ||
|
||
// all environments | ||
app.set('port', process.env.PORT || 3000); | ||
app.set('views', __dirname + '/views'); | ||
app.set('view engine', 'jade'); | ||
app.use(express.favicon()); | ||
app.use(express.logger('dev')); | ||
app.use(express.bodyParser()); | ||
app.use(express.methodOverride()); | ||
app.use(app.router); | ||
// app.use(express.static(path.join(__dirname, 'public'))); | ||
|
||
// development only | ||
if ('development' == app.get('env')) { | ||
app.use(express.errorHandler()); | ||
} | ||
app.configure(function(){ | ||
app.set('port', process.env.PORT || 3000); | ||
app.set('views', __dirname + '/views'); | ||
app.set('view engine', 'jade'); | ||
app.use(express.favicon()); | ||
app.use(express.logger('dev')); | ||
app.use(express.bodyParser()); | ||
app.use(express.methodOverride()); | ||
app.use(app.router); | ||
// app.use(express.static(path.join(__dirname, 'public'))); | ||
}); | ||
|
||
app.get('/', routes.index); | ||
app.get('/users', user.list); | ||
app.get('/hikes', hike.index); | ||
app.post('/add_hike', hike.add_hike); | ||
app.configure('development', function() { | ||
console.log('Using development settings.'); | ||
app.set('connection', mysql.createConnection({ | ||
host: '', | ||
user: '', | ||
port: '', | ||
password: ''})); | ||
app.use(express.errorHandler()); | ||
}); | ||
|
||
http.createServer(app).listen(app.get('port'), function(){ | ||
console.log('Express server listening on port ' + app.get('port')); | ||
app.configure('production', function() { | ||
console.log('Using production settings.'); | ||
app.set('connection', mysql.createConnection({ | ||
host: process.env.RDS_HOSTNAME, | ||
user: process.env.RDS_USERNAME, | ||
password: process.env.RDS_PASSWORD, | ||
port: process.env.RDS_PORT})); | ||
}); | ||
|
||
function init() { | ||
app.get('/', routes.index); | ||
app.get('/users', user.list); | ||
app.get('/hikes', hike.index); | ||
app.post('/add_hike', hike.add_hike); | ||
|
||
http.createServer(app).listen(app.get('port'), function(){ | ||
console.log("Express server listening on port " + app.get('port')); | ||
}); | ||
} | ||
|
||
var client = app.get('connection'); | ||
async.series([ | ||
function connect(callback) { | ||
client.connect(callback); | ||
}, | ||
function clear(callback) { | ||
client.query('DROP DATABASE IF EXISTS mynode_db', callback); | ||
}, | ||
function create_db(callback) { | ||
client.query('CREATE DATABASE mynode_db', callback); | ||
}, | ||
function use_db(callback) { | ||
client.query('USE mynode_db', callback); | ||
}, | ||
function create_table(callback) { | ||
client.query('CREATE TABLE HIKES (' + | ||
'ID VARCHAR(40), ' + | ||
'HIKE_DATE DATE, ' + | ||
'NAME VARCHAR(40), ' + | ||
'DISTANCE VARCHAR(40), ' + | ||
'LOCATION VARCHAR(40), ' + | ||
'WEATHER VARCHAR(40), ' + | ||
'PRIMARY KEY(ID))', callback); | ||
}, | ||
function insert_default(callback) { | ||
var hike = {HIKE_DATE: new Date(), NAME: 'Hazard Stevens', | ||
LOCATION: 'Mt Rainier', DISTANCE: '4,027m vertical', WEATHER:'Bad'}; | ||
client.query('INSERT INTO HIKES set ?', hike, callback); | ||
} | ||
], function (err, results) { | ||
if (err) { | ||
console.log('Exception initializing database.'); | ||
throw err; | ||
} else { | ||
console.log('Database initialization complete.'); | ||
init(); | ||
} | ||
}); |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
var uuid = require('node-uuid'); | ||
|
||
exports.index = function(req, res) { | ||
res.render('hike', {title: 'My Hiking Log'}); | ||
res.app.get('connection').query( 'SELECT * FROM HIKES', function(err, rows) { | ||
if (err) { | ||
res.send(err); | ||
} else { | ||
console.log(JSON.stringify(rows)); | ||
res.render('hike', {title: 'My Hiking Log', hikes: rows}); | ||
}}); | ||
}; | ||
|
||
exports.add_hike = function(req, res) { | ||
exports.add_hike = function(req, res){ | ||
}; |
This file contains 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