meducation / front-end

Meducation Front End Code (currently dormant)
GNU Affero General Public License v3.0
0 stars 1 forks source link

Tidying server.coffee #9

Closed iHiD closed 10 years ago

iHiD commented 11 years ago

I'd like to OO server.coffee a little bit. Here is an example implementation. It doesn't work the Grunt task. @pads - Any idea how to make it work? :sailboat:

class Server
  express = require("express")
  path = require("path")
  http = require("http")

  initialize: ->
    @app = express()
    configure()
    setup_routes()
    start_server()

  configure: ->
    @app.set "port", process.env.PORT || 3000

    # Log requests to the console
    @app.use express.logger "dev"

    # Allow the app to read JSON from the body in POSTs and PUTs
    @app.use express.bodyParser()

    # OS-agnostic way of going up two directories
    # to be able to access the lib and vendor folders
    @app.use express.static path.join __dirname, "..", ".."

  setup_routes: ->
    @app.get "/", (request, response) ->
      response.sendfile path.join "src", "app", "index.html"

    # Add more routes here

  start_server: ->
    http.createServer(app).listen @app.get("port"), () ->
      console.log "Server listening on port: " + @app.get "port"

new Server()
pads commented 10 years ago

This file has changed greatly since the issue was raised. There is more refactoring to do but it's low priority at the moment so I will just leave this open as an enhancement.

pads commented 10 years ago

The job of this server is eventually going to be part of a test Rails instance.