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

It works fine on the web, but I can't get it on the server #320

Open
selvinzr opened this issue Feb 24, 2023 · 7 comments
Open

It works fine on the web, but I can't get it on the server #320

selvinzr opened this issue Feb 24, 2023 · 7 comments
Labels
question Further information is requested

Comments

@selvinzr
Copy link

selvinzr commented Feb 24, 2023

It works fine on the web, but I can't get it on the server

server/colors/[id].ts
export default defineEventHandler(async (event)=>{ const { find } = useStrapi4() return ''; })

500 useStrapi4 is not defined

@selvinzr selvinzr added the question Further information is requested label Feb 24, 2023
@selvinzr selvinzr changed the title It works fine on the front end, but I can't get it on the server It works fine on the web, but I can't get it on the server Feb 24, 2023
@atinux
Copy link
Contributor

atinux commented Mar 4, 2023

The module does not export server functions at the moment.

You can use $fetch in the server route to call the Strapi API in the meantime.

In the future we shall export useServerStrapi()

@kwiat1990
Copy link

kwiat1990 commented Apr 17, 2023

@atinux as the module uses already ohmyfetch, I wonder what would be then required to make it work on the server as well? I'm also interested in this functionality as I don't want to expose Strapi URL on the frontend and perhaps take advantage of the server to make additional work like validation.

Copy link
Contributor

atinux commented Apr 17, 2023

One way is to proxy your API endpoint in Nuxt with routeRules and set the base_URL to your proxy endpoint

@kwiat1990
Copy link

I took a look at proxies but for now I didn't managed to find a working solution really. But masking API endpoint is rather a small part of the "issue". I think the main advantage of letting running the module also on the server is everything what one could do with data, validation and other stuff. I'm looking forward to useServerStrapi.

@kwiat1990
Copy link

kwiat1990 commented May 1, 2023

@atinux with such nuxt.config.ts:

  strapi: {
    cookieName: "user_jwt",
    url: "/api/cms",
    prefix: "",
  },

  routeRules: {
    "/api/cms/**": {
      proxy: {
        to: `${process.env.STRAPI_URL}/api/**`,
      },
    },
  },

I was able to proxy Strapi server to api/cmsand successfully fetch Strapi collections. But how I make social providers authentication work with this approach? For social providers the default URL is http://localhost:1337/api/connect/<providerName>. With the above proxy it is mapped to http://localhost:3000/api/cms/connect/<providerName>, which doesn't work - for example, I get Google login screen, but I won't get redirected to Google's URL as in the default case and the login can't be finished due to bunch of error visible in the console. Any Idea how I could make it work?

@ArtemKolychev
Copy link

I have the same problem.
Node version is 18.
"nuxt": "3.4.3",
"@nuxtjs/strapi": "1.9.3" and tested "1.9.1"
Error message:

   status: 500,
   name: 'UnknownError',
   message: 'fetch failed (admin:3000/api/about-us?fields[0]=aboutUs)',
   details: FetchError: fetch failed (admin:3000/api/about-us?fields[0]=aboutUs)
       at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
       at async $fetch2 (file:///var/www/fe/node_modules/ofetch/dist/shared/ofetch.d438bb6f.mjs:239:15)
       at async /var/www/fe/node_modules/@nuxtjs/strapi/dist/runtime/composables/useStrapiClient.mjs:44:14
       at async setup (/var/www/fe/app.vue:25:34)
 }```

@ArtemKolychev
Copy link

Ok. My error. I start my app in docker compose and i remember add http:// for address.
My runtime config:

  runtimeConfig: {
    strapi: {
      url: `http://strapi:${process.env.ADMIN_PORT}`
    },
    public: {
      strapi: {
        url: `https://${process.env.HOST}:${process.env.STRAPI_PORT}`
      },
    },
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants