-
Notifications
You must be signed in to change notification settings - Fork 37
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
feat: add getStore function used in nuxt.config.js #300
base: main
Are you sure you want to change the base?
feat: add getStore function used in nuxt.config.js #300
Conversation
packages/theme/nuxt.config.js
Outdated
const store = await getStore({ | ||
backendUrl: serverConfig.backendUrl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for not replacing nuxt.config.js with .ts extension? We're lacking type safety in many places here, eg. const store: any
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean type inference works here anyway because of how typescript is configured in this project. But yes we should change that here and in all the other places where files are defined as .js
. I'll make a separate PR for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
packages/theme/nuxt.config.js
Outdated
|
||
dotenv.config({ path: `./../../.env.${process.env.NODE_ENV}` }); | ||
|
||
const serverConfig = { | ||
port: process.env.PORT || 3000, | ||
host: process.env.HOST || '0.0.0.0', | ||
baseUrl: process.env.BASE_URL || 'http://localhost:3000' | ||
baseUrl: process.env.BASE_URL || 'http://localhost:3000', | ||
backendUrl: process.env.BACKEND_URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding base
to the variable name (backendBaseUrl
) to emphasize its potential structure. Or even storeBaseUrl
since backend is not that self-explainatory in my opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that might be confusing since technically we also have the Nuxt backend. I would opt for storeBaseUrl
. Changing the env variable name would be a breaking change though (BACKEND_URL
) and it might confuse developers who are already using the integration.
@rafalcymerys What do you think?
packages/theme/getStore.ts
Outdated
supportedLocales: string | ||
} | ||
|
||
const apiRoute = '/api/v2/storefront/store'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still thinking about this tight coupling of the API route. getStore
returns Store
based on the given StoreConfig
. This gives us enough flexibility to provide our custom base-url of the store-api, however, not enough to have custom route, which could be limiting in some edge cases.
I'd rather see passing the API route as one of the StoreConfig
parameters. We could make it optional with /api/v2/storefront/store
as a default value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Placing that apiRoute
in the nuxt.config
would be also easier to find if someone wanted to modify it. On the other hand, I don't think this endpoint will change since it's specific to how Spree is constructed internally.
I'll move it to nuxt.config
and we can rethink it later.
Description
This PR adds a helper that fetches the Spree store configuration from the api that is then being passed to the nuxt.config.js. This is done to avoid static VSF configuration as much as possible.
There are a few crucial parts of the configuration that the api response is missing data for:
When it comes to loading this config dynamically on each page load, the available locales for i18n module have to be defined in nuxt.config.js (docs). The currencies and meta tags could be loaded dynamically from the app. But splitting this logic between nuxt.config and components seems a bit messy to me, besides it won't solve the problem of having to restart the vsf server.
We could put all of the store config initialisation into the nuxt.config file (as it is now) and set up a redeployment with webhooks every time the store configuration in Spree changes. Technically only rerunning
yarn start
would be enough but that is up to the hosting platform.Related Issue
Motivation and Context
How Has This Been Tested?
visually
Screenshots (if appropriate):
Types of changes
Checklist: