After creating the user class where only the get method is defined, I encountered an issue when using it in middleware. There were no errors during the call to the class, but upon running the code, a "server not found" message appeared. Surprisingly, deleting the line app.use(userRoute) resolved the server error.
users.ts
import { NextFunction, Request, Response } from 'express';
import { Controller, Get, Req, Res } from 'routing-controllers'
@Controller()
class User {
@Get('/signup')
signUP(@Req() req: Request, @Res() res: Response, next: NextFunction) {
return res.render('signup')
};
}
export { User as userRoute }
app.ts
const express = require('express')
const path = require('path')
const app = express()
import { userRoute } from "./routes/user";
const bodyPaser = require('body-parser')
app.use(bodyPaser.urlencoded({ extended: true }))
app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'ejs')
app.use(userRoute)
app.use('/', (req, res) => {
res.write('<html lang="eng">');
res.write('<head><title>Page</title><style>body{background-color: wheat; color: red; font- size: 25px; padding-left: 250px;}.d{}</style></head>')
res.write('<body><h1>It is working</h1></body>')
res.write('</html>')
return res.end()
});
app.listen('3000')
console.log('working')