Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

13-controllers #25

Open
wants to merge 17 commits into
base: 01-basic-setup
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added a logger (morgan), nodemon and error handling
Maximilian Schwarzmüller committed Nov 27, 2017

Verified

This commit was signed with the committer’s verified signature.
myk002 Myk
commit 81ad2b7f1cad7dc49012df4b3ad548b53b999969
1 change: 1 addition & 0 deletions api/routes/orders.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const express = require('express');
const router = express.Router();

// Handle incoming GET requests to /orders
router.get('/', (req, res, next) => {
res.status(200).json({
message: 'Orders were fetched'
19 changes: 19 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
const express = require('express');
const app = express();
const morgan = require('morgan');

const productRoutes = require('./api/routes/products');
const orderRoutes = require('./api/routes/orders');

app.use(morgan('dev'));

// Routes which should handle requests
app.use('/products', productRoutes);
app.use('/orders', orderRoutes);

app.use((req, res, next) => {
const error = new Error('Not found');
error.status = 404;
next(error);
})

app.use((error, req, res, next) => {
res.status(error.status || 500);
res.json({
error: {
message: error.message
}
});
});

module.exports = app;
2,276 changes: 2,276 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -4,7 +4,8 @@
"description": "A Node.js RESTful API Tutorial Project (Build a simple shop API)",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon server.js"
},
"keywords": [
"node",
@@ -14,6 +15,10 @@
"author": "Maximilian Schwarzmüller",
"license": "ISC",
"dependencies": {
"express": "^4.16.2"
"express": "^4.16.2",
"morgan": "^1.9.0"
},
"devDependencies": {
"nodemon": "^1.12.1"
}
}