Refactor & unit tests
This commit is contained in:
27
src/index.ts
Normal file
27
src/index.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import {unwrapMethod, guard} from './utilities/guard.ts';
|
||||
import auth from "./endpoints/auth.ts";
|
||||
import user from "./endpoints/user.ts";
|
||||
|
||||
const server = Bun.serve({
|
||||
routes: {
|
||||
"/api/auth/login": {
|
||||
POST: unwrapMethod(auth.login),
|
||||
},
|
||||
"/api/auth/test": {
|
||||
GET: guard(auth.test, ['ADMIN', 'USERS_OTHER_DELETE'])
|
||||
},
|
||||
"/api/user": {
|
||||
POST: guard(user.create, ['ADMIN', 'USERS_CREATE'])
|
||||
},
|
||||
"/api/user/:id": {
|
||||
GET: guard(user.get, ['ADMIN', 'USERS_OTHERS_READ', 'USERS_SELF_READ'])
|
||||
},
|
||||
},
|
||||
|
||||
// (optional) fallback for unmatched routes:
|
||||
fetch(request: Request): Response {
|
||||
return Response.json({message: "Not found"}, {status: 404});
|
||||
},
|
||||
});
|
||||
|
||||
console.log(`Server running at ${server.url}`);
|
||||
Reference in New Issue
Block a user