From 1964be3fc8af5d8347e58a47bfd39ea81cf6f9cb Mon Sep 17 00:00:00 2001 From: Haris Razis Date: Sun, 3 Jan 2021 09:38:09 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9E=95=20Add=20API=20routes=20for=20athletes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/connections/mongo_conn.js | 1 + server/index.js | 4 +++- server/routes/athletes.js | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/server/connections/mongo_conn.js b/server/connections/mongo_conn.js index 1a4fb98..9fe765f 100644 --- a/server/connections/mongo_conn.js +++ b/server/connections/mongo_conn.js @@ -3,6 +3,7 @@ const chalk = require('chalk') const {mongo_uri} = require('../config/keys'); require('../models/User'); +require('../models/Athlete'); mongoose.Promise = global.Promise; mongoose.connect(mongo_uri, { diff --git a/server/index.js b/server/index.js index 10ee245..5db37cb 100644 --- a/server/index.js +++ b/server/index.js @@ -6,11 +6,12 @@ const cors = require('cors') const history = require('connect-history-api-fallback'); const rateLimit = require('express-rate-limit'); -require('./services/socket')(server); require('./connections/mongo_conn'); +require('./services/socket')(server); const dataRoute = require('./routes/data') const authRoute = require('./routes/auth') +const athletesRoute = require('./routes/athletes') const passport = require('./services/passport'); const {session_secret} = require('./config/keys'); @@ -43,6 +44,7 @@ app.use(passport.session(undefined)); app.use(dataRoute) app.use(authRoute) +app.use(athletesRoute) app.use(history({ verbose: true diff --git a/server/routes/athletes.js b/server/routes/athletes.js index 72be1a0..3c75de9 100644 --- a/server/routes/athletes.js +++ b/server/routes/athletes.js @@ -5,7 +5,7 @@ const {requireAuth} = require('../middlewares/middleware'); const Athlete = mongoose.model('Athlete'); -router.get('/api/athletes', async (req, res) => { +router.get('/api/athletes', requireAuth, async (req, res) => { const athletes = await Athlete.find(); res.send(athletes); });