hoangvvo / next-connect

The TypeScript-ready, minimal router and middleware layer for Next.js, Micro, Vercel, or Node.js http/http2
https://www.npmjs.com/package/next-connect
MIT License
1.63k stars 65 forks source link

Cannot read property 'url' of undefined #112

Closed IRediTOTO closed 3 years ago

IRediTOTO commented 3 years ago

Hi I got this error. Not sure what is the url ?

error in getStaticProps TypeError: Cannot read property 'url' of undefined
    at Function.handle (D:\Job\anz\node_modules\next-connect\lib\index.js:58:21)
    at D:\Job\anz\node_modules\next-connect\lib\index.js:53:12
    at new Promise (<anonymous>)
    at Function.run (D:\Job\anz\node_modules\next-connect\lib\index.js:52:12)
    at getStaticProps (D:\Job\anz\.next\server\pages\index.js:9301:69)
    at renderToHTML (D:\Job\anz\node_modules\next\dist\next-server\server\render.js:27:115)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async D:\Job\anz\node_modules\next\dist\next-server\server\next-server.js:98:66
    at async __wrapper (D:\Job\anz\node_modules\next\dist\lib\coalesced-function.js:1:330)

here is my use

await all.run(context.req, context.res);
const items = await getItems(context.req.db, 0, 8);
IRediTOTO commented 3 years ago

Error above said about at getStaticProps (D:\Job\anz\.next\server\pages\index.js:9301:69) And I got this at line 9301 await src_middlewares_index__WEBPACK_IMPORTED_MODULE_3__["all"].run(context.req, context.res);

IRediTOTO commented 3 years ago

It dont make site down but try catch got this :)

IRediTOTO commented 3 years ago
nc.handle = function handle(req, res, done) {
    const idx = req.url.indexOf("?");   // bug here ? 
    const pathname = idx !== -1 ? req.url.substring(0, idx) : req.url;
    const { handlers } = this.find(
      req.method,
      this.baseUrl ? pathname.substring(this.baseUrl.length) : pathname
    );
IRediTOTO commented 3 years ago

Oh no :) This don't run in getStaticProps

IRediTOTO commented 3 years ago

OMG :) New version connect mongo supper fast ,it like a production.