{"size": 1692, "ext": "js", "max_stars_repo_path": "router.js", "max_stars_repo_name": "Krinto/ChipIn-Api", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "router.js", "max_issues_repo_name": "Krinto/ChipIn-Api", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "router.js", "max_forks_repo_name": "Krinto/ChipIn-Api", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.7636363636, "max_line_length": 103, "alphanum_fraction": 0.5685579196}
var express = require('express');
var passport = require('passport');

var groupsCountroller = require('./controllers/groups');
var authController = require('./controllers/auth');

module.exports = function(app) {
    app.use(passport.initialize());
    require('./config/passport')(passport);

    var apiRoutes = express.Router();
    var authRoutes = express.Router();
    var groupRoutes = express.Router();

    // ====================================================
    // Auth Routes

    apiRoutes.use('/auth', authRoutes);

    // Registration route
    authRoutes.post('/register', authController.register);

    // Login route
    authRoutes.post('/authenticate', authController.authenticate);

    // ====================================================
    // Test Routes
    apiRoutes.get('/', function (req, res) {
        res.json({message: 'Hello World'}); 
    });

    apiRoutes.get('/protected', passport.authenticate('jwt', { session: false }), function (req, res) {
        res.json({message: 'Success the user id is: ' + req.user._id }); 
    });

    // ====================================================
    // Group Routes

    apiRoutes.use('/group', groupRoutes);
    groupRoutes.use(passport.authenticate('jwt', { session: false }));

    groupRoutes.get('/', groupsCountroller.getAllGroups);

    groupRoutes.post('/', groupsCountroller.createGroup);

    groupRoutes.get('/:id', groupsCountroller.getGroup);

    groupRoutes.put('/:id', groupsCountroller.updateGroup);

    groupRoutes.delete('/:id', groupsCountroller.deleteGroup);

    // ====================================================
    // Base url for api routes
    app.use('/api', apiRoutes);
}