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

Nuxt systematically inits the API in production where it could only when needed #134

Closed
gabrielsze opened this issue Apr 3, 2021 · 3 comments · Fixed by #137
Closed
Labels
enhancement New feature or request

Comments

@gabrielsze
Copy link

A reference to an issue raised earlier here - #77,
especially highlighted in this comment

I am only including the plugin in modules of nuxt config and my app is universal. Not all the pages are using this plugin, only one page called /blog. Even the root of the website is blocked when there is no prismic related calls in index file. To init the API on load I tried to inject it as plugin instead of using in modules (the Vue way) but then it is not available for the server side rendering.

This is an issue for me because I'm only utilising prismic in one of my subdirectories example.com/blog. However, when I generate many other pages in other subdirectories example.com/pages1,example.com/pages2 etc, the prismic API key is somehow always called, resulting in many API calls incurred (thousands of pages generated), and this error is thrown many times.

 ERROR  Failed to init Prismic API, preventing app fatal error.                            23:26:10


 ERROR  request to https://<REPO NAME>.cdn.prismic.io/api/v2?routes=%5B%7B%22type%22%3A%22post%22%2C%22path%22%3A%22%2Fblog%2F%3Auid%22%7D%5D failed, reason: write EPROTO 4534230528:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:


  
  at ClientRequest.<anonymous> (node_modules/node-fetch/lib/index.js:1461:11)
  at ClientRequest.emit (events.js:311:20)
  at ClientRequest.EventEmitter.emit (domain.js:482:12)
  at TLSSocket.socketErrorListener (_http_client.js:426:9)
  at TLSSocket.emit (events.js:311:20)
  at TLSSocket.EventEmitter.emit (domain.js:482:12)
  at errorOrDestroy (internal/streams/destroy.js:108:12)
  at onwriteError (_stream_writable.js:462:5)
  at onwrite (_stream_writable.js:483:5)
  at internal/streams/destroy.js:50:7
  at TLSSocket.Socket._destroy (net.js:673:5)
  at TLSSocket.destroy (internal/streams/destroy.js:38:8)
  at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:93:12)

Is there a way to only include the API calls for pages which only require them?

@lihbr
Copy link
Collaborator

lihbr commented Apr 3, 2021

Hey @gabrielsze, thanks for raising your concerns regarding that and taking the time to look for duplicates.

As of writing this there's unfortunately no way to achieve that using this module.

A workaround would be to scale down to @prismicio/vue which might give you more control but might not be as straightforward to use as this module.

However with the new version of @prismicio/client we're now recommending to init the API through the .client method that comes with the benefit initing the API only when needed. We'll check if that's possible to migrate this module API init process to this method without introducing breaking changes.

Let us know if anything!

@lihbr lihbr added the enhancement New feature or request label Apr 3, 2021
@lihbr lihbr changed the title nuxt generate always calls api multiple times Nuxt systematically inits the API in production where it could only when needed Apr 12, 2021
@lihbr lihbr added the good first issue Good for newcomers label Apr 19, 2021
@lihbr
Copy link
Collaborator

lihbr commented May 4, 2021

Update 05/04/2021:

  1. I attempted to migrate the API init process to .client while working on v1.3 #137. Unfortunately, I discovered a lot of small breaking changes related to this refactor, it mainly changes the way to access the internals of the client (see: https://github.com/prismicio/prismic-javascript/blob/HEAD/src/ResolvedApi.ts#L55-L64) which might cause trouble to some users. As a result of that I introduced a new modern option coming with v1.3 #137 that will allow you to opt-in this feature while also disabling legacy stuff on the module automatically 🚀

@lihbr lihbr added v3 Getting addressed or related to version 3 of the kit enhancement New feature or request and removed enhancement New feature or request good first issue Good for newcomers labels May 4, 2021
lihbr added a commit that referenced this issue May 4, 2021
@lihbr lihbr added available soon and removed v3 Getting addressed or related to version 3 of the kit labels May 4, 2021
@lihbr
Copy link
Collaborator

lihbr commented May 4, 2021

Just updated my previous comment as I had an idea about it, landing soon 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants