Browse Source

Add API routes for athletes

main
Haris Razis 4 years ago
parent
commit
1964be3fc8
  1. 1
      server/connections/mongo_conn.js
  2. 4
      server/index.js
  3. 2
      server/routes/athletes.js

1
server/connections/mongo_conn.js

@ -3,6 +3,7 @@ const chalk = require('chalk')
const {mongo_uri} = require('../config/keys'); const {mongo_uri} = require('../config/keys');
require('../models/User'); require('../models/User');
require('../models/Athlete');
mongoose.Promise = global.Promise; mongoose.Promise = global.Promise;
mongoose.connect(mongo_uri, { mongoose.connect(mongo_uri, {

4
server/index.js

@ -6,11 +6,12 @@ const cors = require('cors')
const history = require('connect-history-api-fallback'); const history = require('connect-history-api-fallback');
const rateLimit = require('express-rate-limit'); const rateLimit = require('express-rate-limit');
require('./services/socket')(server);
require('./connections/mongo_conn'); require('./connections/mongo_conn');
require('./services/socket')(server);
const dataRoute = require('./routes/data') const dataRoute = require('./routes/data')
const authRoute = require('./routes/auth') const authRoute = require('./routes/auth')
const athletesRoute = require('./routes/athletes')
const passport = require('./services/passport'); const passport = require('./services/passport');
const {session_secret} = require('./config/keys'); const {session_secret} = require('./config/keys');
@ -43,6 +44,7 @@ app.use(passport.session(undefined));
app.use(dataRoute) app.use(dataRoute)
app.use(authRoute) app.use(authRoute)
app.use(athletesRoute)
app.use(history({ app.use(history({
verbose: true verbose: true

2
server/routes/athletes.js

@ -5,7 +5,7 @@ const {requireAuth} = require('../middlewares/middleware');
const Athlete = mongoose.model('Athlete'); 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(); const athletes = await Athlete.find();
res.send(athletes); res.send(athletes);
}); });

Loading…
Cancel
Save