You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
/**
|
|
|
|
* Developer API
|
|
|
|
* - Users
|
|
|
|
* - Resources
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { Router, Request, Response, NextFunction } from 'express';
|
|
|
|
import { findFromToken, users } from '../auth';
|
|
|
|
import { data } from '../data';
|
|
|
|
|
|
|
|
const RouterApi = Router();
|
|
|
|
const RouterUser = Router();
|
|
|
|
const RouterResource = Router();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Token authentication middleware
|
|
|
|
*/
|
|
|
|
const authMiddleware = (req: Request, res: Response, next: NextFunction) => {
|
|
|
|
const user = findFromToken(req.headers.authorization ?? '');
|
|
|
|
(user && user.admin)
|
|
|
|
? next()
|
|
|
|
: res.sendStatus(401);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const onStart = () => {
|
|
|
|
RouterApi.use('/user', RouterUser);
|
|
|
|
RouterApi.use('/resource', RouterResource);
|
|
|
|
|
|
|
|
return RouterApi;
|
|
|
|
};
|