Created
December 17, 2012 01:58
-
-
Save todoubled/4315262 to your computer and use it in GitHub Desktop.
Mock server for local development
This file contains hidden or 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
# | |
# Use a fixture stub of JSON to mock a headline API to respond to GET /headline | |
# | |
fs = require 'fs' | |
express = require 'express' | |
root = require('path').normalize "#{__dirname}/.." | |
pub = "#{root}/app/public" | |
headline = JSON.parse fs.readFileSync "#{root}/app/fixtures/headline-api.json", 'utf8' | |
module.exports = routes = express() | |
# --- | |
routes.get '/headline', (req, res) -> | |
res.send headline |
This file contains hidden or 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
# | |
# ## Server | |
# | |
# ###### Mock API endpoints and serve static assets in `app/public`. | |
# | |
# --- | |
# | |
# - Define custom routes with `routesPath` for API endpoints. | |
# - Mock edge-case result sets for fast, offline integration tests. | |
# | |
fs = require 'fs' | |
express = require 'express' | |
root = require('path').normalize "#{__dirname}/.." | |
routesPath = "routes.coffee" | |
port = process.env.PORT || 8080 | |
app = express() | |
app.use app.router | |
app.use express.static pub | |
app.use express.bodyParser() | |
# Use any custom routes if they're defined. | |
app.use require(routesPath) if fs.existsSync routesPath | |
# Allow the integration test runner to run at a different port to avoid collision with `make server` on `8080`. | |
app.listen port |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment