veliovgroup / spiderable-middleware

🤖 Prerendering for JavaScript powered websites. Great solution for PWAs (Progressive Web Apps), SPAs (Single Page Applications), and other websites based on top of front-end JavaScript frameworks
https://www.npmjs.com/package/spiderable-middleware
BSD 3-Clause "New" or "Revised" License
38 stars 4 forks source link

TypeError: app.use() requires a middleware function #21

Closed gustawdaniel closed 8 months ago

gustawdaniel commented 8 months ago

I added

import Spiderable from 'meteor/ostrio:spiderable-middleware';

WebApp.connectHandlers.use(
    new Spiderable({
        rootURL: 'https://a8a2-176-74-87-61.ngrok-free.app',
        serviceURL: 'https://render.ostr.io',
        auth: 'APIUser:APIPass'
    })
);

and see this error:

W20240310-15:29:13.171(4)? (STDERR) TypeError: app.use() requires a middleware function
W20240310-15:29:13.171(4)? (STDERR)     at Function.use (/home/daniel/.meteor/packages/webapp/.2.0.0-beta300.0.fqumlc.j85e5++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/express/lib/application.js:217:11)
W20240310-15:29:13.171(4)? (STDERR)     at module.wrapAsync.self (server/ssr.tsx:40:24)
W20240310-15:29:13.171(4)? (STDERR)     at Module.wrapAsync (/home/daniel/.meteor/packages/modules/.0.19.1-beta300.0.28ut9u.9egzk++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/@meteorjs/reify/lib/runtime/index.js:251:8)
W20240310-15:29:13.171(4)? (STDERR)     at module (/home/daniel/pro/mrr/.meteor/local/build/programs/server/app/app.js:53964:9)
W20240310-15:29:13.171(4)? (STDERR)     at fileEvaluate (packages/modules-runtime.js:335:7)
W20240310-15:29:13.171(4)? (STDERR)     at Module.require (packages/modules-runtime.js:237:14)
W20240310-15:29:13.171(4)? (STDERR)     at Module.mod.require (/home/daniel/.meteor/packages/modules/.0.19.1-beta300.0.28ut9u.9egzk++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/@meteorjs/reify/lib/runtime/index.js:30:33
)                                                          
W20240310-15:29:13.171(4)? (STDERR)     at Object.require (packages/modules-runtime.js:257:21)
W20240310-15:29:13.171(4)? (STDERR)     at evaluateNextModule (packages/core-runtime.js:183:26)
W20240310-15:29:13.171(4)? (STDERR)     at evaluateNextModule (packages/core-runtime.js:218:7)
W20240310-15:29:13.171(4)? (STDERR)     at evaluateNextModule (packages/core-runtime.js:218:7)
W20240310-15:29:13.171(4)? (STDERR)     at evaluateNextModule (packages/core-runtime.js:218:7)
W20240310-15:29:13.171(4)? (STDERR)     at evaluateNextModule (packages/core-runtime.js:218:7)
W20240310-15:29:13.171(4)? (STDERR)     at evaluateNextModule (packages/core-runtime.js:218:7)
W20240310-15:29:13.171(4)? (STDERR)     at evaluateNextModule (packages/core-runtime.js:218:7)
W20240310-15:29:13.171(4)? (STDERR)     at evaluateNextModule (packages/core-runtime.js:218:7)
=> Exited with code: 1                                     

I am using Meteor 3

dr-dimitru commented 8 months ago

Hello @gustawdaniel ,

Try spiderable.handler.bind(spiderable) as described in express-middleware example.

This is due to the fact Meteor 3 has changed middleware library.

Let me know if it works properly

gustawdaniel commented 8 months ago

I confirm it works. For further readers.:

import Spiderable from 'meteor/ostrio:spiderable-middleware';

const spiderable = new Spiderable({
    rootURL: 'https://myservice.com',
    serviceURL: 'https://render.ostr.io',
    auth: 'user:pass',
});

WebApp.connectHandlers.use(spiderable.handler.bind(spiderable));

Thanks @dr-dimitru for super fast support.