mirror of https://github.com/tycrek/ass
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.
42 lines
885 B
42 lines
885 B
/**
|
|
* Developer API
|
|
* - Users
|
|
* - Resources
|
|
*/
|
|
|
|
import { Router, Request, Response, NextFunction } from 'express';
|
|
import { findFromToken, users } from '../auth';
|
|
import { data } from '../data';
|
|
import { User } from '../types/auth';
|
|
|
|
/**
|
|
* The primary API router
|
|
*/
|
|
const RouterApi = Router();
|
|
|
|
/**
|
|
* Token authentication middleware for Admins
|
|
*/
|
|
const adminAuthMiddleware = (req: Request, res: Response, next: NextFunction) => {
|
|
const user = findFromToken(req.headers.authorization ?? '');
|
|
(user && user.admin) ? next() : res.sendStatus(401);
|
|
};
|
|
function buildUserRouter() {
|
|
const userRouter = Router();
|
|
|
|
return userRouter;
|
|
}
|
|
|
|
function buildResourceRouter() {
|
|
const resourceRouter = Router();
|
|
|
|
return resourceRouter;
|
|
}
|
|
|
|
export const onStart = () => {
|
|
RouterApi.use('/user', buildUserRouter());
|
|
RouterApi.use('/resource', buildResourceRouter());
|
|
|
|
return RouterApi;
|
|
};
|