Help wanted: Setting up controllers: {ControllerName}
raulmax319 opened this issue · 3 comments
raulmax319 commented
Help wanted: Setting up controllers: {ControllerName}
raulmax319 commented
Hi, I need help on getting my server up using overnightjs, when using the method super.addControllers
the server won't boot up and the log shows only a message Setting up controller:
ControllerName``
raulmax319 commented
here is the Server class:
import express from 'express';
import { Server } from '@overnightjs/core';
import { Router } from '~/routes';
import { logger } from './utils/logger';
import { HelloWorldController } from './controllers/hello-world/hello-world.controller';
class CoreServer extends Server {
private readonly PORT = process.env.PORT ?? 3001;
private readonly log = logger;
constructor() {
super(process.env.NODE_ENV === 'development');
this.showLogs = true;
this.applyMiddlewares();
this.setupControllers();
}
private setupControllers(): void {
const helloController = new HelloWorldController();
super.addControllers([helloController]);
}
private applyMiddlewares = () => {
this.app.use(express.json());
};
public start() {
this.app.listen(this.PORT, () => {
this.log.detail(`Server is running on port ${this.PORT}`);
});
}
}
Here's the Controller:
import { Controller, Get, Post } from '@overnightjs/core';
import { NextFunction, Request, Response } from 'express';
import { logger } from '~/utils/logger';
@Controller('/hello')
export class HelloWorldController {
@Get('/')
private getHello = (
req: Request,
res: Response,
next: NextFunction,
): Response<{ ok: boolean; message: string }> | undefined => {
try {
const response = { ok: true, message: 'helloWorld' };
return res.send(response);
} catch (e) {
return res.status(500).send({ ok: false, message: e.message });
}
};
}
raulmax319 commented
I have found the issue, changed the log detail to console log