Permalink
Browse files

Upgraded to Express 3.x

  • Loading branch information...
1 parent dded678 commit 2070adaa832f89480934a60845d743ce8d0d4cd7 @hectorcorrea committed Sep 10, 2012
Showing with 96 additions and 30 deletions.
  1. +30 −22 app.coffee
  2. +3 −3 data/blogs.json
  3. +24 −0 logs/2012_09_09.txt
  4. +2 −2 package.json
  5. +4 −0 views/404.ejs
  6. +4 −0 views/500.ejs
  7. +3 −1 views/about.ejs
  8. +4 −0 views/blogAll.ejs
  9. +4 −0 views/blogOne.ejs
  10. +4 −0 views/blogRecent.ejs
  11. +5 −1 views/blogedit.ejs
  12. +3 −1 views/home.ejs
  13. +6 −0 views/layout.ejs
View
52 app.coffee
@@ -1,34 +1,47 @@
# Module dependencies.
express = require 'express'
+path = require 'path'
ejs = require 'ejs'
+http = require 'http'
+
{Logger} = require './util/logger'
siteRoutes = require './routes/siteRoutes'
blogRoutes = require './routes/blogRoutes'
logRoutes = require './routes/logRoutes'
-app = module.exports = express.createServer()
+
+app = express()
# Configuration
app.configure ->
- app.set 'views', __dirname + '/views'
- app.set 'datapath', __dirname + '/data'
+ app.set 'port', process.env.PORT || 3000
+ app.set 'views', path.join(__dirname, 'views')
+ app.set 'datapath', path.join(__dirname, 'data')
# Configure view engine options
ejs.open = '{{'
ejs.close = '}}'
app.set 'view engine', 'ejs'
- #app.use express.logger() # logs HTTP requests
+ app.use express.favicon()
+ app.use express.logger('dev')
+
app.use express.bodyParser()
app.use express.methodOverride()
- app.use express.static(__dirname + '/public') # must come before app.router!
+
+ app.use express.cookieParser('your secret here')
+ app.use express.session()
+
+ # static handler must come before app.router!
+ app.use express.static path.join(__dirname, 'public')
+
app.use app.router
-app.error (err, req, res, next) ->
- Logger.error err
- res.render '500.ejs', { status: 500, message: "TBD" }
+# app.error (err, req, res, next) ->
+# Logger.error err
+# res.render '500.ejs', { status: 500, message: "TBD" }
app.configure 'development', ->
@@ -39,10 +52,7 @@ app.configure 'production', ->
app.use express.errorHandler()
-# Routes
-app.get '/', siteRoutes.home
-app.get '/about', siteRoutes.about
-
+# Application settings
app.set "isReadOnly", if app.settings.env is "production" then true else false
app.set "dataOptions", {
dataPath: __dirname + "/data"
@@ -51,6 +61,10 @@ app.set "dataOptions", {
}
+# Routes
+app.get '/', siteRoutes.home
+app.get '/about', siteRoutes.about
+
if not app.settings.isReadOnly
# Only enable edits when in development (local)
# until I integrate an authentication process
@@ -75,14 +89,8 @@ app.get '/logs/', logRoutes.viewCurrent
app.get '*', siteRoutes.notFound
# Fire it up!
-app.listen process.env.PORT || 3000, ->
- address = "http://localhost:#{app.address().port}"
+server = http.createServer(app)
+port = app.get('port')
+server.listen port, ->
+ address = "http://localhost:#{port}"
Logger.info "Express server listening on #{address} in #{app.settings.env} mode"
-
-
-
-
-
-
-
-
View
6 data/blogs.json
@@ -1,11 +1,11 @@
{ "nextId": 32, "blogs":[
{
"id": 31,
- "title": "beyond hello world pu",
+ "title": "beyond hello world xxx",
"createdOn": "2012-09-08T14:01:12.964Z",
- "updatedOn": "2012-09-09T20:51:27.964Z",
+ "updatedOn": "2012-09-10T01:53:50.991Z",
"postedOn": null,
- "url": "beyond-hello-world-pu",
+ "url": "beyond-hello-world-xxx",
"summary": "this is the summary"
},
{
View
24 logs/2012_09_09.txt
@@ -115,3 +115,27 @@
2012-09-09 18:39:39.386 INFO: Express server listening on http://localhost:3000 in development mode
2012-09-09 18:39:39.002 INFO: blogRoutes:viewAll
2012-09-09 18:52:52.273 INFO: blogRoutes:viewOne beyond-hello-world-pu
+2012-09-09 21:39:39.161 INFO: Express server listening on http://localhost:3000 in development mode
+2012-09-09 21:39:39.393 INFO: blogRoutes:viewRecent
+2012-09-09 21:39:39.401 INFO: blogRoutes:viewOne a-decaf-introduction-to-coffeescript
+2012-09-09 21:42:42.538 INFO: blogRoutes:viewOne a-decaf-introduction-to-coffeescript
+2012-09-09 21:49:49.803 INFO: blogRoutes:viewRecent
+2012-09-09 21:50:50.604 INFO: blogRoutes:viewRecent
+2012-09-09 21:50:50.926 INFO: blogRoutes:viewAll
+2012-09-09 21:52:52.194 INFO: blogRoutes:viewAll
+2012-09-09 21:52:52.719 INFO: blogRoutes:viewRecent
+2012-09-09 21:52:52.826 INFO: blogRoutes:viewAll
+2012-09-09 21:53:53.967 INFO: blogRoutes:viewAll
+2012-09-09 21:53:53.724 INFO: blogRoutes:viewRecent
+2012-09-09 21:53:53.091 INFO: blogRoutes:viewOne a-decaf-introduction-to-coffeescript
+2012-09-09 21:53:53.758 INFO: blogRoutes:edit a-decaf-introduction-to-coffeescript
+2012-09-09 21:53:53.535 INFO: blogRoutes:viewRecent
+2012-09-09 21:53:53.568 INFO: blogRoutes:viewOne beyond-hello-world-pu
+2012-09-09 21:53:53.591 INFO: blogRoutes:edit beyond-hello-world-pu
+2012-09-09 21:53:53.986 INFO: blogRoutes:save 31
+2012-09-09 21:53:53.079 INFO: Saved, redirecting to /blog/beyond-hello-world-xxx
+2012-09-09 21:53:53.121 INFO: blogRoutes:viewOne beyond-hello-world-xxx
+2012-09-09 21:53:53.652 INFO: blogRoutes:viewRecent
+2012-09-09 21:54:54.438 INFO: blogRoutes:viewRecent
+2012-09-09 21:54:54.537 INFO: blogRoutes:viewOne beyond-hello-world-xxx
+2012-09-09 21:54:54.789 INFO: blogRoutes:viewRecent
View
4 package.json
@@ -3,8 +3,8 @@
"version": "0.0.1-7",
"private": true,
"dependencies": {
- "express": "= 2.5.8",
- "ejs": "~0.7.2",
+ "express": "= 3.0.0rc4",
+ "ejs": "0.8.2",
"rss": "0.0.4"
},
"subdomain": "simple-blog",
View
4 views/404.ejs
@@ -1,4 +1,8 @@
+{{ include layoutTop }}
+
<h1>Page not found</h1>
<p>Sorry, the page that you are looking for does not exist.</p>
<p>{{message}}
+{{ include layoutBottom }}
+
View
4 views/500.ejs
@@ -1,4 +1,8 @@
+{{ include layoutTop }}
+
<h1>Oops! Something went wrong</h1>
<p>{{= message}}</p>
<p>The end</p>
+{{ include layoutBottom }}
+
View
4 views/about.ejs
@@ -1,3 +1,4 @@
+{{ include layoutTop }}
<div class="row">
<div class="eight columns">
<h3>About Hector Correa</h3>
@@ -21,4 +22,5 @@
<li><a href="blog/rss" target="_blank">Blog Feed</a></li>
</ul>
</div>
-</div>
+</div>
+{{ include layoutBottom }}
View
4 views/blogAll.ejs
@@ -1,3 +1,5 @@
+{{ include layoutTop }}
+
<div class="row">
<div class="eight columns">
@@ -35,3 +37,5 @@
</p>
</div>
</div>
+
+{{ include layoutBottom }}
View
4 views/blogOne.ejs
@@ -1,3 +1,5 @@
+{{ include layoutTop }}
+
<div class="row">
<div class="twelve columns">
<h3>{{= topic.meta.title }}</h3>
@@ -32,4 +34,6 @@
</div>
</div>
+{{ include layoutBottom }}
+
View
4 views/blogRecent.ejs
@@ -1,3 +1,5 @@
+{{ include layoutTop }}
+
<div class="row">
<div class="eight columns">
@@ -35,3 +37,5 @@
</p>
</div>
</div>
+
+{{ include layoutBottom }}
View
6 views/blogedit.ejs
@@ -1,3 +1,5 @@
+{{ include layoutTop }}
+
{{ postUrl = isNaN(topic.meta.id) ? "/blog/new" : "/blog/save/" + topic.meta.id }}
<h1>Blog</h1>
@@ -66,4 +68,6 @@
<p>ID {{= topic.meta.id }} <p/>
</fieldset>
-</form>
+</form>
+
+{{ include layoutBottom }}
View
4 views/home.ejs
@@ -1,3 +1,4 @@
+{{ include layoutTop }}
<div class="row">
<div class="eight columns">
<h3>Welcome to HectorCorrea.com</h3>
@@ -12,4 +13,5 @@
</div>
-</div>
+</div>
+{{ include layoutBottom }}
View
6 views/layout.ejs
@@ -1,5 +1,11 @@
<!DOCTYPE html>
+<!--
+ This document is now obsolete.
+ See layoutTop.ejs and layoutBottom.ejs instead
+-->
+
+
<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->

0 comments on commit 2070ada

Please sign in to comment.