June 2018
Intermediate to advanced
348 pages
8h 19m
English
To list our matches, we won't need security, because all the users should be able to get the full list of matches in the applications. So let's implement the matches API.
So, create a new file called matches-api.js into the src/routes folder and apply the following code:
const express = require('express')const api = express.Router()const Match = require('../models/match')api .route('/matches') .get((req, res, next) => { Match.find().exec() .then(matches => res.json(matches)) .catch(err => next(err)) })module.exports = api
Next, we have to configure the server.js file to map our Match APIs. In the server.js file, apply the following change:
...const adminApi = require('./src/routes/admin-api')const matchesApi = require('./src/routes/matches-api') ...Read now
Unlock full access