Spartacus running dev:ssr on multisite not passing requestOrigin from the NgExpressEngineDecorator - spartacus-storefront

I'm running a Spartacus SSR Multisite.
This works fine when I'm running yarn build:ssr and yarn serve:ssr.
The Spartacus NgExpressEngineDecorator nicely passes the original hostname to the application.
But when I run yarn dev:ssr for debugging purposes, this fails.
The SERVER_REQUEST_ORIGIN always returns localhost or 127.0.0.1.
https://github.com/SAP/spartacus/blob/develop/core-libs/setup/ssr/engine-decorator/ng-express-engine-decorator.ts#L108
So the baseSite can't be found.
Setting "host" and "publicHost" options on the "serve-ssr" in angular.json doesn't seem to help either. Any ideas how we can solve this issue?
If I have a decent way to debug the multisite SSR, I'd be very happy.

As #Krzysztof Platis mentioned, putting server.set('trust proxy', 'loopback'); in server.ts is what solved my problem

Related

Expo application doesn't get changes in .env file

I have an Expo managed react native application. I created my .env file in the root of my project, installed react-native-dotenv and set up babel to use it. After a while I managed to get it to work.
I have my environment variable
ENDPOINT=http://127.0.0.1:8000/api
and i use it with
process.env.ENDPOINT
After a while I decided to test the android version of the app, so i changed the endpoint url to my LAN ip and restarted the server. The problem is that even after restarting the server, the cache and the computer, when I call process.env.ENDPOINT it keeps the first url I set.
Here's a list of the things i tried:
restarting the server
restarting the server and the cache
restarting the whole computer
change the variable name to REACT_APP_ENDPOINT as many suggested (I get undefined, it's still stuck to ENDPOINT)
empty expo cache
The strange thing is that I already changed that same variable twice (from 127.0.0.1:8000 to 127.0.0.1:8080 and back for a problem with backend) and had the same problem, but it went away by itself after a couple of minutes (and server restarts).
This time I've been trying to get it to work for 7 hours and nothing has changed.
Any idea?
I had the same issue and managed to run the app with .env changes after using the following command.
expo r -c
reference: https://github.com/goatandsheep/react-native-dotenv/issues/75#issuecomment-728055969
After a couple hundred more tests I gave up and implemented a "custom" solution, without any external library:
Switched .env files to TypeScript files (E.g. .env.development -> env.development.ts)
Set up an object named env that has all environmental variables as properties
export const env = {
VAR1: 'foo',
...
}
Imported this constant inside the application entry point (in my case App.tsx)
Inside the main constructor assign env to global.env
Use global.env instead of process.env
Not sure if this is the best practice, but solved my problem for now, works like a charm and doesn't require me to reload my application at every change. I'm a bit concerned by the security aspect of having the environment in a global variable inside a js project, so any suggestion is still welcome

Webpack configuration intermittently working

Yesterday I've struggled the whole day with my webpack configuration.
I've got a apache serving my php pages, with a proxy setup in webpack-dev-server config.
The problem is that when I load the page, the bundle is found, but apparently is like its not running at all!
After a change in the configuration, it did work, and I tought that the problem was solved, but today, after changing a single line, the problem occurred again!
After going back to the working configuration, nothing changed.
What the....? Please if anybody can give me any kind of suggestion, I'll appreciate that.
The application is made with Vue js, and in the browser console there's no message at all.
Thank you.
OK,
I'm sorry for the mistake, but for an unknown reason, my configuration file did go back to a previous version and I noticed the fact just now.
After repeating the change did Yesterday, the problem disappeared. I lost half of my day figuring out the problem that blocked the script execution, so I share the part of the code I had to remove in order to get a working configuration.
I'd like to know if anybody knows, why this piece of code is preventing the scripts in the bundle from running.
optimization: {
runtimeChunk: 'single',
splitChunks : {
chunks: 'all'
}
},
Thank you all.

How to use npm start on remote dev box with create-react-app

I would like to know how to use the create-react-app "npm start" script when development takes place on a remote host.
Nginx is running as a reverse proxy. The external uri looks like:
https://my-dev-box/my-cra
which is set to proxy to:
http://localhost:3000
The CRA app is static (ie no API calls).
The errors appearing in the browser's web dev console are 404s related to /static/js/bundle.js and favicon. The app's index.html page is served with a 200 response.
When I build the app, "npm build" produces an index.html file with the correct paths (courtesy of the "homepage" setting in package.json). I have looked at the documentation/tickets surrounding "Invalid Host Header" and "DANGEROUSLY_DISABLE_HOST_CHECK" but have not found a combo which works for me.
It appears to me that the fundamental issue is that "npm start" does not seem aware (as "npm build" is aware) that the WebDevServer is behind a proxy and is thus not constructing correct paths for resources.
So to restate the question, does anyone know how to get "npm start" working nicely behind a reverse proxy on remote development box. (create-react-app version used: 1.5.2)
(Note: application works perfectly behind proxy when using "npm build".)
Update: Courtesy of this question I found this comment in "webpack.config.dev.js":
// Webpack uses `publicPath` to determine where the app is being served from.
// In development, we always serve from the root. This makes config easier.
const publicPath = '/';
which I guess means that what I want to do is not going to be that practical unless I eject the project. (Which I'm a little reluctant to do - the reason for using create-react-app is newness to React.)

Sylius themes not showing on channels

I have followed the steps to create themes according to Sylius doc.
After run php bin/console sylius:theme:assets:install, login to backend, but no theme showing under channel.
Any ideas? Thanks!
I have found out the reason. Some how the clear cache default on dev environment but actually I only have prod environment.
After cleared cache on prod:
php bin/console --env=prod --no-debug cache:clear
the theme showing up.
Also, since I cannot find how to setup dev env, I have cloned the prod db to sylius_dev and run:
http://[my ip]/app_dev.php
If you are not using 127.0.0.1, you need to add to:
\web\app_dev.php
Hope this help for someone new to Sylius and Symphony like me.

Getting DEPTH_ZERO_SELF_SIGNED_CERT in my browserify react app

Having problems doing requests over invalid SSL from my browserify react app, I basically have this issue: https://github.com/request/request/issues/418 as I'm using request.
I have tried setting both strictSSL=false and rejectUnauthorized=false but it doesn't work.
The other solution was to set the environment variable NODE_TLS_REJECT_UNAUTHORIZED to 0. But I can't do that in my browserify/envify environment.
Help!
Ok. It turned out that the strictSSL setting did work. The problem was that request depends on the node package https which was not included in the browserify bundle. So as soon as I added https to the build and set the strictSSL setting to false it worked perfectly. Hope that helped somebody else!