Slight restructure, updated auth, implement player and game endpoints
This commit is contained in:
31
src/index.ts
31
src/index.ts
@@ -1,27 +1,26 @@
|
||||
import {unwrapMethod, guard} from './utilities/guard';
|
||||
import auth from "./endpoints/auth";
|
||||
import user from "./endpoints/user";
|
||||
import auth from './routes/auth';
|
||||
import user from './routes/user';
|
||||
import player from './routes/player';
|
||||
import game from './routes/game';
|
||||
import { OkResponse } from './utilities/responseHelper';
|
||||
|
||||
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'])
|
||||
...auth,
|
||||
...user,
|
||||
...player,
|
||||
...game,
|
||||
'/test': {
|
||||
GET: (request) => {
|
||||
return new OkResponse();
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// (optional) fallback for unmatched routes:
|
||||
fetch(): Response {
|
||||
return Response.json({message: "Not found"}, {status: 404});
|
||||
return Response.json({ message: 'Not found' }, { status: 404 });
|
||||
},
|
||||
});
|
||||
|
||||
console.log(`Server running at ${server.url}`);
|
||||
console.log(`Server running at ${server.url}`);
|
||||
|
||||
Reference in New Issue
Block a user