How to set the default language of the Spartacus storefront? - spartacus-storefront

The Spartacus storefront has english as default language, i couldn't find a way to change this within the i18n settings in my app.module.ts, is there another way to set another language as default?

You can configure this in the context properties. There are two possibilities:
static, configured via javascript, see https://sap.github.io/cloud-commerce-spartacus-storefront-docs/static-context-configuration/
automatic, configured via site setup in SAP Commerce, see https://sap.github.io/cloud-commerce-spartacus-storefront-docs/automatic-context-configuration/

Related

Disabling default canonical URL handling

is there a way to disable the default canonical URL handling within SAP Spartacus?
It appears that since 4.x a default behavior has been integrated.
For the page type 'ProductPage' the 'setCanonicalLink()' in the 'PageMetaLinkService' is still triggered and removes our custom set canonical tag
Changing the settings in the config, as described in the documentation is not doing anything for the ProductPage: https://sap.github.io/spartacus-docs/html-tags/#canonical-urls
Cheers

Is It Possible to Have a Meaningful/Secure Content Security Policy With Next.js + Styled-Components and a Static Host (eg. S3)

Recently Google's Lighthouse tool alerted me to the fact that I wasn't providing a Content Security Policy. However, when I try to add one (or at least one without the word "unsafe" in it), I wind up with a bunch of violations, seemingly coming from Next.js and Styled-Components.
Both libraries seem to use dynamic script/style tags which violate any sane CSP. But the only way I've found to work around them is to use a "nonce". However, that seems to require having an actual server running: if you're using Next to generate static files (to host on a static host like AWS S3), you can't provide nonces.
My question is simple: am I missing anything? Is there some non-nonce-based way, or a static-host-nonce-based way, to host a site on S3 using Next.js and Styled Components?
Or is it just impossible to use those libraries together with a strict CSP (without a server-generated nonce)?
I hope you:
do not use inline styles like <tag style='display:none;'> or JS call of element.setAttribute('style', ...).
do not use built-in inline event handlers like <tag onclick='...'> and JS-navigation like <a href='javascript:void(0)'>
because all of above require 'unsafe-inline' in styles/scripts respectively since 'unsafe-hashes' token is not supported by Safary and bugly supported by Firefox.
For Single Page Applications (SPA) (without server-side rendering), using 'nonce-value' is not useful, because the SPA does not reload the page, but only partially updates its contents, but you must generate new nonce for each page loading.
For serverless apps (like static file hosting) and SPA apps you can use 'hash-value' instead of 'nonce-value' to allow inline scripts and styles.
If you use Webpack, it has some plugins, for instance, csp-html-webpack-plugin plugin will generate content for your Content Security Policy meta tag and input the correct data into your HTML template, generated by html-webpack-plugin. All inline JS and CSS will be hashed, and inserted into the policy.

swagger API documentation with my own yaml file

I have my API documented with Swagger. For developer convenience I would like to provide the swagger GUI on my website as well. However, my provider has not installed the php yaml extension. It implies that I can't use the GUI on my own website.
So, I would like to use a third party GUI. I know that I can use https://petstore.swagger.io/ and enter the link to my yaml file in the text box. This is also not really user friendly. I prefer to open the GUI and specify the yaml when calling the url. For the user the GUI opens with my API definition.
Any thoughts?
If for some reason you cannot host Swagger UI youself, here are some alternatives you can try:
Use SwaggerHub to host your API definition and docs.
Disclosure: I work for the company that makes SwaggerHub.
Use GitLab to host your OpenAPI YAML/JSON file. GitLab uses Swagger UI to render OpenAPI files. Example:
https://gitlab.com/gofus/gofus-api/blob/dev/swagger.yaml
Use https://petstore.swagger.io with the url query parameter to automatically load your API definition:
https://petstore.swagger.io?url=https://yoursite.com/api.yaml
For this to work, the server where your OpenAPI file is hosted must use HTTPS and support CORS.

JS storefront URL is picked up for OCC_BACKEND_BASE_URL_VALUE"

Running into very strange situation with the Spartacus setup on CCV2. After setting up the meta placeholder in the index.html file:
I setup the baseURL as null in environment.ts and environment.prod.ts, just to be double sure.
baseUrl: null,
It seems to work, but the problem is when storefront is deployed, JS store is picking up the JS storefront URL for content load
https://JS Storefront URL/XXXwebservices/v2/SITE/cms/pages
My understanding is that it should be ACC Storefront URL:
https://ACC Storefront URL/XXXwebservices/v2/SITE/cms/pages
Is there any other setting that needs to be made? Other than the ones identified above? do we need any other configuration on the CCV2 side of things?
The initial answer below didn't make too much sense, let me retry:
I recommend to leave out the baseUrl in the configuration completely, as the current behaviour prioritises the configuration over the meta-tag. See https://github.com/SAP/spartacus/issues/5886 for more info.
While the MEDIA_BACKEND_BASE_URL_VALUE has been added in Spartacus to distinguish the api and media, CCv2 has not yet implemented this feature. See also https://github.com/SAP/spartacus/issues/2212#issuecomment-490089609.
This is why the Spartacus side of it works, but the media base Url doesn't get injected on ccv2.

How to use external file to modify a variable when the app is in production?

I have a web page made with .Net Core 2.1 and Vue, when the web application is in production mode, how to leave a config file as the Net Core appsettings.json and modify a variable.
My doubt is also about how to build the content of it, and how to access to that variable in one of my component page in vue.
Thank you
Sounds like what you may be after is External Configuration Store pattern
https://learn.microsoft.com/en-us/azure/architecture/patterns/external-configuration-store
This will allow you to store the configuration information in external storage, and provide an interface that can be used to quickly and efficiently read and update configuration settings