-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathserver.js
62 lines (48 loc) · 1.65 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* Server script for Express web application framework. Loads a custom routes
* module with REST API and MongoDB integration, for prototyping CRUD operations
* with RESTful back-end.
*
* DEV URL: http://localhost:9001/
*
* @author Aki Karkkainen
* Adapted from the following sources (among others):
* http://addyosmani.github.io/backbone-fundamentals/#creating-the-back-end
* https://npmjs.org/package/grunt-express
* http://mongoosejs.com/docs/index.html
* Single Page Web Applications book: http://www.manning.com/mikowski/
* @url https://github.com/akikoo/grunt-frontend-workflow
* Twitter: http://twitter.com/akikoo
*
*/
// Module dependencies.
var approot = __dirname,
// Public www root.
webroot = 'www',
// Web framework.
express = require('express'),
// Routes module.
routes = require('./routes'),
// Utilities for dealing with file paths.
path = require('path'),
// Express server instance.
app;
// Create server.
app = express();
// Configure server.
app.configure(function () {
// Parse request body and populate request.body.
app.use(express.bodyParser());
// Check request.body for HTTP method overrides.
app.use(express.methodOverride());
// Perform route lookup based on URL and HTTP method.
app.use(app.router);
// Where to serve static content.
app.use(express.static(path.join(approot, webroot)));
// Show all errors in development.
app.use(express.errorHandler({dumpExceptions: true, showStack: true}));
});
// Invoke `routesConf` method to set up the routes.
routes.routesConf(app);
// Export the server module.
module.exports = app;