Creating new route for an Endpoint.
After i created a new endpoint with yo angular-fullstack:endpoint i wanted to create some routes.
Thats what my new index.js looks like:
'use strict';
import {Router} from 'express';
import * as controller from './question.controller';
import * as auth from '../../auth/auth.service';
var router = new Router();
router.get('/', controller.index);
router.get('/:id', auth.hasRole('admin'), controller.show);
router.get('/my', controller.my);
router.post('/', auth.isAuthenticated(), controller.create);
router.put('/:id', auth.hasRole('admin'), controller.update);
router.patch('/:id', auth.hasRole('admin'), controller.update);
router.delete('/:id', auth.hasRole('admin'), controller.destroy);
export default router;
everything works except for router.get('/my', controller.my);.
I added a export function my(req, res, next) in question.controller.js.
The error i receive is: UnauthorizedError: No authorization token was found.
It's like the middleware is calling auth.isAuthenticated() in the /my route even though it is not supposed to.
When i look at the template 'user'-endpoint, the router.get('/me', controller.me); works fine, but not for my new endpoint.
What am i missing here?
Sorry i found my error. I had to put router.get('/my', controller.my); before router.get('/:id', auth.hasRole('admin'), controller.show); like this:
router.get('/my', controller.my);
router.get('/:id', auth.hasRole('admin'), controller.show);
Yeah, since it has the same syntax as /:id, you have to put it first.