-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
33 lines (27 loc) · 942 Bytes
/
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
let express = require('express');
let app = express();
let morgan = require('morgan');
let bodyParser = require('body-parser');
let port = process.env.PORT || 3000;
let pet = require('./routes/pet');
//don't show the log when it is test
if(process.env.NODE_ENV !== 'test') {
//use morgan to log at command line
app.use(morgan('combined')); //'combined' outputs the Apache style LOGs
}
//parse application/json and look for raw text
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.text());
app.use(bodyParser.json({ type: 'application/json'}));
app.get("/", (req, res) => res.json({message: "Welcome to our Petstore!"}));
app.route("/pets")
.get(pet.getPets)
.post(pet.postPet);
app.route("/pets/:id")
.get(pet.getPet)
.delete(pet.deletePet)
.put(pet.updatePet);
app.listen(port);
console.log("Listening on port " + port);
module.exports = app; // for testing