-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserver.js
More file actions
65 lines (51 loc) · 2.02 KB
/
Copy pathserver.js
File metadata and controls
65 lines (51 loc) · 2.02 KB
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
63
64
65
//require modules
var express = require('express'),
bodyParser = require('body-parser'),
db = require('./models'),
controllers = require('./controllers'),
app = express();
//parse incoming urlencoded form data and populate the req.body object
app.use(bodyParser.urlencoded({extended: true}));
// allow cross origin requests (optional)
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
/************
* DATABASE *
************/
var db = require('./models');
/**********
* ROUTES *
**********/
// Serve static files from the `/public` directory:
// i.e. `/images`, `/scripts`, `/styles`
app.use(express.static('public'));
/*
* HTML Endpoints
*/
app.get('/', function homepage(req, res) {
// res.send("The server is up and running");
res.sendFile('./views/index.html', {root: __dirname});
});
app.get('/neighborhoods/', function neighborhoods(req, res) {
// res.send("The server is up and running");
res.sendFile('./views/neighborhoods.html', {root: __dirname});
});
/*
* JSON API Endpoints
*/
app.get('/api', controllers.api.index);
app.get('/api/neighborhoods', controllers.neighborhoods.neighborhoods_index);
app.get('/api/neighborhoods/:hoodId', controllers.neighborhoods.neighborhoods_show);
app.get('/api/neighborhoods/:hoodId/places', controllers.places.index);
app.post('/api/neighborhoods/:hoodId/places', controllers.places.create);
app.get('/api/neighborhoods/:hoodId/places/:placeId', controllers.places.show);
app.patch('/api/neighborhoods/:hoodId/places/:placeId', controllers.places.update);
app.delete('/api/neighborhoods/:hoodId/places/:placeId', controllers.places.destroy);
// listen on the port that Heroku prescribes (process.env.PORT) OR port 3000
app.listen(process.env.PORT || 3000, function () {
console.log('Express server is up and running on http://localhost:3000/');
});