Skip to content

Instantly share code, notes, and snippets.

@TotallyInformation
Created April 25, 2012 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TotallyInformation/2488283 to your computer and use it in GitHub Desktop.
Save TotallyInformation/2488283 to your computer and use it in GitHub Desktop.
Failing to find asset with Connect-assets, Express, CoffeScript
# app.coffee
# We will call this automatically via `node server.js`
# this instanstiates the CoffeeScript compiler and automatically runs app.coffee through it & runs the resulting app.js
# Using `forever server.js` will reload server.js whenever there is a change to a file in the applications folders so we don't have to stop and restart the server when something changes.
# @see http://blogs.planetsoftware.com.au/felix/archive/2012/03/08/coffeeeeeeee.aspx
# -- Require our libaries --
express = require 'express'
#https = require 'https'
# Auto compile of client code written in CoffeeScript or js (js), Stylus or less (css)
# NB: Compiled code is stored in memory not on disk, far future expiry is set with hash in url to allow chg
#
assets = require 'connect-assets'
coffeekup = require 'coffeekup' # CoffeeKup templating
# Read our environment dependent settings
env = require './.env.js'
# Set the options that force a secure (https) server
options = env.certs
# Create the (https) server
app = module.exports = express.createServer(options)
# Register our views as being 'coffee' files, and also set
# the rendering of these files to be delegated to coffeekup
#app.configure ->
app.set 'views', __dirname + '/views'
app.set 'view engine', 'coffee'
app.register '.coffee', coffeekup.adapters.express
# Use connect-assests to serve up our client side js
# however it supports writing it in coffeescript
app.use assets()
# Routes - divert base page to the helloworld.coffee view
app.get '/', (req, res) ->
# NB: Layouts depricated in Express v3 so don't use them now
res.render 'helloworld', {layout: false}
# For Express <v3 listen on port 8000 (or override with environment setting) - access via https://localhost:8000 on your browser
app.listen process.env.VMC_APP_PORT or 8000, -> console.log "Listening on #{app.address().port} ..."
# This will be needed for Express v3
#https.createServer(options, app).listen process.env.VMC_APP_PORT or 8000, ->
# console.log "'"Listening on #{app.address().port} ..."
doctype 5
html ->
head ->
title 'Hello world'
text js 'clientlib'
body ->
div '#id.class', ->
'Hello World'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment