Skip to content

vite.config.js issue with prod env (last update where localhost replaces server.host) #530

@romeof1980

Description

@romeof1980

Issue summary

Using the template in order to build a custom shopify app works smoothly and deploying to render.com works mostly fine but calling /api/products/count fails with 401 if authorization is needed (i.e. where reading data from shopify session)

Expected behavior

Having the result of the product count when calling web endpoint /api/products/count

Actual behavior

401 Unauthorized (nginx log)

Steps to reproduce the problem

  1. test the app works smoothly locally (via 'shopify app dev') where it calls GET /api products/count and POST /api/products
  2. after step 1 confirmed ok: deploy in render (Dockerfile and nginx.conf double checked? yes. set env vars on render? yes)
  3. check the app is deployed correctly (static files are all 200) and any custom web endpoint (where auth is not needed) gives 200
  4. call /api/products/count (in the ProductsCard.jsx react component): the count and button will keep loading and the console will give 401 unauthorized for /api/products/count

Possible solution (tested)

we solved via modifying web/frontend/vite.config.js reverting the following update cited in the Readme:

2. Change the server.host setting in the configs to "localhost":
server: {
  host: "localhost",

with this fix (on hosting service render.com or any other service with similar issue)

#reverting to server.host for production envs
server: {
  host: "server.host"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions