Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/worker/src/http/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Application } from "express";
import gaslessRouter from "./modules/gasless/routes";
import { handleErrors } from "./middlewares/handleErrors";

export const setupRoutes = (app: Application): void => {
app.use("/worker/gasless", gaslessRouter);

app.use(handleErrors);
};
22 changes: 22 additions & 0 deletions packages/worker/src/http/middlewares/handleErrors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Request, Response, NextFunction } from "express";

export class AppError extends Error {
constructor(public readonly statusCode: number, message: string) {
super(message);
this.name = "AppError";
}
}

export const handleErrors = (
err: Error,
_req: Request,
res: Response,
_next: NextFunction
): void => {
if (err instanceof AppError) {
res.status(err.statusCode).json({ error: err.message });
return;
}

res.status(500).json({ error: "Internal server error" });
};
16 changes: 16 additions & 0 deletions packages/worker/src/http/modules/gasless/controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Request, Response, NextFunction } from "express";
import { AppError } from "@/http/middlewares/handleErrors";

export class GaslessController {
static async reserve(
_req: Request,
res: Response,
next: NextFunction
): Promise<void> {
try {
throw new AppError(501, "Not implemented");
} catch (err) {
next(err);
}
}
}
8 changes: 8 additions & 0 deletions packages/worker/src/http/modules/gasless/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Router } from "express";
import { GaslessController } from "@/http/modules/gasless/controller";

const gaslessRouter = Router();

gaslessRouter.post("/reserve", GaslessController.reserve);

export default gaslessRouter;
4 changes: 4 additions & 0 deletions packages/worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
UserBlockSyncCron,
} from "./queues/userBlockSync";
import { GaslessUtxoCleanup } from "@/queues/gaslessUtxos/gaslessUtxoCleanup";
import { setupRoutes } from "@/http";

const {
WORKER_PORT,
Expand Down Expand Up @@ -54,6 +55,9 @@ console.log(
);

const app = express();
Comment thread
GabrielTozatti marked this conversation as resolved.
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
setupRoutes(app);
const serverAdapter = new ExpressAdapter();

createBullBoard({
Expand Down
Loading