Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NextJS Guide? #18

Open
FTCHD opened this issue Feb 24, 2024 · 12 comments
Open

NextJS Guide? #18

FTCHD opened this issue Feb 24, 2024 · 12 comments

Comments

@FTCHD
Copy link
Contributor

FTCHD commented Feb 24, 2024

I'd love to be the one to add it but I'm not so familiar with how this should be integrated.

I've integrated prerender in the past and their NextJS middleware is pretty straight forward, not sure if just doing a copy pasta for spiderable would work?

For reference, here are the prerender docs for Next:

Ideally, we edit Next middleware to check if the request is a bot, and if so we send it to Ostr for prerendering.

This is a touchy topic (regarding SEO and not screwing up page/domain scores), so that why I'm reticent to do it without the proper experience of how spiderable works.

This would potentially unlock a lot of new users, right now NextJS users have only one easy/default option.

@FTCHD
Copy link
Contributor Author

FTCHD commented Feb 24, 2024

I've added an example for Cloudflare Workers in the meantime, should be pretty close to Next: #19

@txprojects88
Copy link

Agree it would be great to have a nextjs example :)

@dr-dimitru
Copy link
Member

@FTCHD @txprojects88 have you tried?

In NextJS project's root directory create middleware.js:

import { NextResponse } from "next/server";
import Spiderable from 'spiderable-middleware';

const spiderable = new Spiderable({
  rootURL: 'http://example.com',
  auth: 'APIUser:APIPass'
});

const next () => {
  return NextResponse.next();
};

export async function middleware(req, res) { 
  return spiderable.handler(req, res, next);
};

@txprojects88
Copy link

txprojects88 commented Aug 14, 2024

Get error

Could not find a declaration file for module 'spiderable-middleware'. '/Users/node_modules/spiderable-middleware/lib/index.js' implicitly has an 'any' type. Try npm i --save-dev @types/spiderable-middlewareif it exists or add a new declaration (.d.ts) file containingdeclare module 'spiderable-middleware';`

npm i --save-dev @types/spiderable-middleware did not work

@dr-dimitru
Copy link
Member

@txprojects88 How to use NPM package without Types Definitions?

@txprojects88
Copy link

I declared the module but still getting Error: The edge runtime does not support Node.js 'https' module.
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime

@dr-dimitru
Copy link
Member

@txprojects88 Are you sure you're adding this to server-only environment? Where this error is displayed? Terminal? Browser?

@txprojects88
Copy link

I am using this in the middleware. Error is displayed in browser.

@dr-dimitru
Copy link
Member

@txprojects88 Doesn't sounds right. Hold on I'll try to reproduce on my end. What Router do you use?

@dr-dimitru
Copy link
Member

@txprojects88 And what version of next.js?

@txprojects88
Copy link

app router

@txprojects88
Copy link

14.0.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants