seanpmaxwell / overnight

TypeScript decorators for the ExpressJS Server.
MIT License
878 stars 40 forks source link

cant handle single word route. #35

Closed artoodeeto closed 4 years ago

artoodeeto commented 4 years ago

hello again sir. I really love your work. been using this on my side project. I just want to say thank you for everything.

Anyway I think I found a bug. so on this simple controller the Get() and Get(':id') is working as normal, but when I tried creating the Get('test') and Get('bar') I wont hit or get any response from that route. I have to this make an extension on the route name like bar/foo and test/tst something like that. You cant have a single word on a route? just wanted to let you know. thanks again and I support this. ❤️

im using the version: "@overnightjs/core": "1.6.11",

@Controller('users')
export class UsersController extends BaseController {

  @Get()
  private async getAllUsers(req: Request, res: Response) {
    try {
      res.json({
        users: await User.find()
      });
    } catch (error) {
      res.status(200).json({
        error
      });
    }
  }

  @Get(':id')
  private async getSingleUser(req: Request, res: Response) {
    const { id } = req.params;
    try {
      res.json({
        user: await User.findOneOrFail(id)
      });
    } catch (error) {
      res.json({
        errorMsg: error
      });
    }
  }

  @Get('test')
  @Middleware(JwtManager.middleware)
  private async test(req: ISecureRequest, res: Response) {
    console.log(req.payload)
    res.json({
      samp: 'asdf'
    })
  }

  @Get('bar')
  @Middleware(JwtManager.middleware)
  private async bar(req: ISecureRequest, res: Response) {
    console.log(req.payload)
    res.json({
      samp: 'asdf'
    })
  }

}
seanpmaxwell commented 4 years ago

Hmm I'm not sure what's going on buddy. I just tried out my sample project to make sure it was still working. Here's a file in the sample project where I use a single word route. https://github.com/seanpmaxwell/overnight/blob/master/sample-project/src/controllers/JwtPracticeController.ts. Download the sample project and see if that' works for you.

artoodeeto commented 4 years ago

@seanpmaxwell aight sir. thats weird, ive been debugging it last night I couldn't find any issue. actually theres no error on the route but the error is coming from the model. Its trying to access a bar entity on my models. ill my repo. its really weird. but anyways. thanks.

seanpmaxwell commented 4 years ago

The model huh. Are you is using TypeOrm?

artoodeeto commented 4 years ago

@seanpmaxwell yea. sorry I havent shared my repo. I was busy at work. but yes im using typeorm. ohh nooo. please dont tell me its the ORM. been working on my personal project for about a month now. :sob:

seanpmaxwell commented 4 years ago

TypeOrm is garbage, use raw sql. Well you said the error is happening on the model not the route so I'm going to close this issue as it doesn't seem to be overnight related. good luck!