feat: added inital API structure

Merge pull request #180 from tycrek/0.14.0/api

close https://github.com/tycrek/ass/issues/179
pull/183/head
Josh Moore 2 years ago committed by GitHub
commit 489b497c7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -10,6 +10,7 @@ import tailwindcss from 'tailwindcss';
import helmet from 'helmet';
import { path, log, getTrueHttp, getTrueDomain } from './utils';
import { onStart as ApiOnStart } from './routers/api';
//#endregion
//#region Setup - Run first time setup if using Docker (pseudo-process, setup will be run with docker exec)
@ -105,6 +106,9 @@ ASS_FRONTEND.enabled && app.use(ASS_FRONTEND.endpoint, ASS_FRONTEND.router); //
// Upload router (has to come after custom frontends as express-busboy interferes with all POST calls)
app.use('/', ROUTERS.upload);
// API
app.use('/api', ApiOnStart());
// CSS
app.use('/css', epcss({
cssPath: path('tailwind.css'),

@ -0,0 +1,30 @@
/**
* Developer API
* - Users
* - Resources
*/
import { Router, Request, Response, NextFunction } from 'express';
import { 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 token = req.headers.authorization;
(token && users[token])
? next()
: res.sendStatus(401);
};
export const onStart = () => {
RouterApi.use('/user', RouterUser);
RouterApi.use('/resource', RouterResource);
return RouterApi;
};
Loading…
Cancel
Save