forked from SF-WDI-LABS/express-personal-api
-
Notifications
You must be signed in to change notification settings - Fork 33
/
server.js
59 lines (47 loc) · 1.55 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
// require express and other modules
var express = require('express'),
app = express();
// parse incoming urlencoded form data
// and populate the req.body object
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: true }));
/************
* 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.sendFile(__dirname + '/views/index.html');
});
/*
* JSON API Endpoints
*/
app.get('/api', function api_index(req, res) {
// TODO: Document all your api endpoints below
res.json({
woops_i_has_forgot_to_document_all_my_endpoints: true, // CHANGE ME ;)
message: "Welcome to my personal api! Here's what you need to know!",
documentation_url: "https://github.com/example-username/express_self_api/README.md", // CHANGE ME
base_url: "http://YOUR-APP-NAME.herokuapp.com", // CHANGE ME
endpoints: [
{method: "GET", path: "/api", description: "Describes all available endpoints"},
{method: "GET", path: "/api/profile", description: "Data about me"}, // CHANGE ME
{method: "POST", path: "/api/campsites", description: "E.g. Create a new campsite"} // CHANGE ME
]
})
});
/**********
* SERVER *
**********/
// listen on port 3000
app.listen(process.env.PORT || 3000, function () {
console.log('Express server is up and running on http://localhost:3000/');
});