404 status on every route
Opened this issue · 0 comments
Bartek-Figat commented
Hello, I would like to use OvernightJS in my project. But I ran into an issue where all my routes hit the 404 status code. I wonder if this is my setup fault. I have looked at the documentation for a few times and it seems to me that I did everything correctly. Configuration below.
server.ts
export class SampleServer extends Server {
constructor() {
super();
this.app.use(express.urlencoded({ limit: "50mb", extended: true }));
this.app.use(express.json({ limit: "50mb" }));
this.app.use(compression());
this.app.use(
cors({
methods: ["GET, POST, PUT, DELETE, OPTIONS"],
credentials: true,
origin,
allowedHeaders: [
"Origin, X-Requested-With, Content-Type, Accept, Authorization",
],
})
);
this.app.use(helemt());
this.app.use(morgan("dev"));
this.app.enable("trust proxy");
this.app.use(express.static("avatar"));
this.app.use(
"/api-docs",
swaggerUi.serve,
swaggerUi.setup(swaggerDocument)
);
this.setupControllers();
}
private setupControllers(): void {
const userController = new UserController();
super.addControllers([userController]);
}
public start(port: number): void {
this.app.listen(port, () => {
console.log("Server listening on port: " + port);
});
}
}
server.start(Port);
controller
@Controller("/api/v1")
export default class UserController {
constructor(
private service: UserService = new UserService(),
private addService: AddService = new AddService()
) {}
@Post("user/profile")
async userInsertProfile(req: Request, res: Response, next: NextFunction) {
const response = await this.service.userInsertProfile(req.body, req.user);
res.status(response.statusCode).json(response);
}
@Get("filter")
async filterCategories(
req: Request<{}, {}, {}, ICategories>,
res: Response,
next: NextFunction
) {
const response = await this.addService.filterCategories(req.query);
res.status(response.statusCode).json(response);
}
@Get("data")
async advertisingData(req: Request, res: Response, next: NextFunction) {
const response = await this.addService.advertisingData();
res.status(response.statusCode).json(response);
}
}