angular-architects / module-federation-plugin

MIT License
735 stars 203 forks source link

Running the app on a host other than `localhost` #657

Open ckddbs opened 1 month ago

ckddbs commented 1 month ago

For which library do you need help?

native-federation

Question

I used the below codes in Angular app to run it on custom host such as http://my.local.app:4200/. But it does not work in Native-federation environment.

ng serve --disable-host-check --host=0.0.0.0

For reference, I added the below line into /etc/hosts. 127.0.0.1 my.local.app

rainerhahnekamp commented 1 month ago

Hello, can you connect to it via the normal browser? Do you get an error message and is it reproducible via our stackblitz example?

ckddbs commented 1 month ago

Hello @rainerhahnekamp,

Here are steps to reproduce this issue. Thank you!

Hosts file

  1. Edit /etc/hosts
    
    # Host Database
    #
    # localhost is used to configure the loopback interface
    # when the system is booting.  Do not change this entry.
    ##
    127.0.0.1   localhost
    255.255.255.255 broadcasthost
    ::1             localhost

127.0.0.1 my.local.app.com


**Angular**
1. Create new app `ng new myApp`
2. Change directory `cd myApp`
3. Install packages `npm i`
4. Serve with host option `ng serve --disable-host-check --host=0.0.0.0`
5. Open http://my.local.app.com:4200. And it works well.

**Native Federation**
1. Download `https://github.com/manfredsteyer/module-federation-plugin-example/tree/nf-standalone-solution`
2. Install packages
3. Edit `package.json`
`    "start:all": "concurrently \"ng serve mfe1 --disable-host-check --host=0.0.0.0\" \"ng serve shell --disable-host-check --host=0.0.0.0\""`
5.  Run `npm run start:all`, then below errors occur.

mf-demo@0.0.0 start:all concurrently "ng serve mfe1 --disable-host-check --host=0.0.0.0" "ng serve shell --disable-host-check --host=0.0.0.0"

[0] Error: Unknown arguments: disable-host-check, host [1] Error: Unknown arguments: disable-host-check, host [1] ng serve shell --disable-host-check --host=0.0.0.0 exited with code 1 [0] ng serve mfe1 --disable-host-check --host=0.0.0.0 exited with code 1



<img width="788" alt="Screenshot 2024-10-05 at 10 07 24 AM" src="https://github.com/user-attachments/assets/872b6239-3bb2-451b-954e-782c5db3c92c">
rainerhahnekamp commented 1 month ago

@ckddbs --disable-host-check is not supported by Angular's ApplicationBuilder anymore (esbuild).

please check the angular version your ng new is generating. To be sure to be on the latest version, run npm init @angular@latest

ckddbs commented 1 month ago

@rainerhahnekamp I tested Angular v17 and want to run a native-federation app on a custom domain. Is this currently possible, or are there plans to support this feature?

rainerhahnekamp commented 1 month ago

@ckddbs It is possible to use native federation with Angular v17, but you need to use the ApplicationBuilder and not webpack in your package.json.

What we have to provide, is that native-federation passes on the --host flag to the ApplicationBuilder. You don't need --disable-host-check though.