@syzy/apphost 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +184 -0
- package/dist/__federation_shared_@tanstack/react-query-DHuUsaNz.js +2517 -0
- package/dist/__federation_shared_react-CikWE6qG.js +7 -0
- package/dist/__federation_shared_react-bootstrap-BKlZRvMR.js +7516 -0
- package/dist/__federation_shared_react-dom-vrQ70Ay8.js +372 -0
- package/dist/__federation_shared_react-router-dom-BKminmS4.js +10448 -0
- package/dist/__federation_shared_react-select-B6kehBDI.js +4056 -0
- package/dist/__federation_shared_react-toastify-B0S0UGr3.js +412 -0
- package/dist/_commonjsHelpers-C6fGbg64.js +6 -0
- package/dist/_virtual___federation_fn_import-XZCKozko.js +217 -0
- package/dist/favicon.ico +0 -0
- package/dist/index-DgtWMtjZ.js +184 -0
- package/dist/index-eZknuYwc.js +1219 -0
- package/dist/index.js +15 -0
- package/dist/jsx-runtime-D_t4bG-_.js +264 -0
- package/dist/manifest.webmanifest +1 -0
- package/dist/pwa/Hotel-icon.jpg +0 -0
- package/dist/pwa/apple-touch-icon-180x180.png +0 -0
- package/dist/pwa/favicon.ico +0 -0
- package/dist/pwa/maskable-icon-512x512.png +0 -0
- package/dist/pwa/pwa-192x192.png +0 -0
- package/dist/pwa/pwa-512x512.png +0 -0
- package/dist/pwa/pwa-64x64.png +0 -0
- package/dist/registerSW.js +1 -0
- package/dist/sw.js +1 -0
- package/dist/workbox-1ef09536.js +1 -0
- package/package.json +35 -0
package/README.md
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
## Overview
|
|
2
|
+
|
|
3
|
+
## This project is the App Host application in a micro-frontend architecture using:
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
React + TypeScript
|
|
7
|
+
Vite
|
|
8
|
+
Module Federation (@originjs/vite-plugin-federation)
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
App Host dynamically loads remote micro UIs such as Booking UI, Grocery UI, etc., at runtime.
|
|
12
|
+
Each remote exposes components which App Host consumes through module federation.
|
|
13
|
+
|
|
14
|
+
## Environment Configuration
|
|
15
|
+
|
|
16
|
+
The project uses .env files for environment-specific settings.
|
|
17
|
+
|
|
18
|
+
Example .env file
|
|
19
|
+
|
|
20
|
+
# Uppercase full project name
|
|
21
|
+
APP_NAME=HMS
|
|
22
|
+
|
|
23
|
+
# Remote Booking UI bundle URL
|
|
24
|
+
VITE_BOOKING_UI_REMOTE=http://localhost:4173/dist/assets/booking-UI.js
|
|
25
|
+
|
|
26
|
+
# Remote Booking UI server URL
|
|
27
|
+
VITE_APP_HOST_SERVER_URL=https://jta26gfu55gapk5fbzjtxkvqsi.appsync-api.ap-south-1.amazonaws.com/graphql
|
|
28
|
+
|
|
29
|
+
## Environment Loading
|
|
30
|
+
|
|
31
|
+
VITE_BOOKING_UI_REMOTE tells App Host where to load the remote booking UI bundle.
|
|
32
|
+
|
|
33
|
+
## If not provided, App Host uses:
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
http://localhost:4173/dist/assets/booking-UI.js
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Running the Project
|
|
41
|
+
## Development
|
|
42
|
+
npm run dev
|
|
43
|
+
|
|
44
|
+
## Runs the project on:
|
|
45
|
+
http://localhost:3000
|
|
46
|
+
|
|
47
|
+
## Build
|
|
48
|
+
npm run build
|
|
49
|
+
|
|
50
|
+
## Preview Production Build
|
|
51
|
+
npm run preview
|
|
52
|
+
|
|
53
|
+
## Module Federation Setup
|
|
54
|
+
|
|
55
|
+
App Host uses module federation to load micro UIs at runtime.
|
|
56
|
+
|
|
57
|
+
## Federation Config (App Host)
|
|
58
|
+
|
|
59
|
+
## Below is the configuration snippet from vite.config.ts:
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
export default defineConfig(({ mode }) => {
|
|
63
|
+
// load env for current mode; third arg '' returns all keys (or pass 'VITE_' to filter)
|
|
64
|
+
const env = loadEnv(mode, process.cwd(), '')
|
|
65
|
+
|
|
66
|
+
// access your variable (defined in `.env` as VITE_SUBSCRIPTION_REMOTE)
|
|
67
|
+
const remoteBookingUI = env.VITE_BOOKING_UI_REMOTE ?? 'http://localhost:4173/dist/assets/booking-UI.js'
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
plugins: [react(), federation({
|
|
71
|
+
name: 'App_Host',
|
|
72
|
+
remotes: {
|
|
73
|
+
bookingUIApp: remoteBookingUI
|
|
74
|
+
},
|
|
75
|
+
shared: {
|
|
76
|
+
react: { singleton: true, requiredVersion: false, eager: true } as any,
|
|
77
|
+
'react-dom': { singleton: true, requiredVersion: false, eager: true } as any,
|
|
78
|
+
'react-router-dom': { singleton: true, requiredVersion: false } as any,
|
|
79
|
+
'react-bootstrap': { singleton: true, requiredVersion: false } as any,
|
|
80
|
+
'react-select': { singleton: true, requiredVersion: false } as any,
|
|
81
|
+
"@tanstack/react-query": { singleton: true } as any,
|
|
82
|
+
'react-toastify': { singleton: true, requiredVersion: false, eager: true } as any,
|
|
83
|
+
}
|
|
84
|
+
})],
|
|
85
|
+
server: {
|
|
86
|
+
port: 3000
|
|
87
|
+
},
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Expected Remote Structure (Booking UI / Others)
|
|
93
|
+
|
|
94
|
+
## Every remote micro UI must:
|
|
95
|
+
|
|
96
|
+
1) Use Vite + Module Federation
|
|
97
|
+
|
|
98
|
+
2) Expose components as federated modules
|
|
99
|
+
|
|
100
|
+
3) Build and host a bundle file such as:
|
|
101
|
+
|
|
102
|
+
```js
|
|
103
|
+
booking-UI.js
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Remote Micro UI Example (Booking UI)
|
|
107
|
+
```js
|
|
108
|
+
federation({
|
|
109
|
+
name: "bookingUIApp",
|
|
110
|
+
filename: "booking-UI.js",
|
|
111
|
+
exposes: {
|
|
112
|
+
"./AmenityForm": "./src/components/AmenityForm.tsx",
|
|
113
|
+
"./RoomCategoryForm": "./src/components/RoomCategoryForm.tsx",
|
|
114
|
+
"./ExtraRequirementForm": "./src/components/ExtraRequirementForm.tsx",
|
|
115
|
+
"./ReservationForm": "./src/components/ReservationForm.tsx",
|
|
116
|
+
"./CreateRoomForm": "./src/components/CreateRoomForm.tsx"
|
|
117
|
+
},
|
|
118
|
+
shared: ["react", "react-dom"]
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Importing Remote Components (Inside App Host)
|
|
123
|
+
|
|
124
|
+
Once the remote bundle is loaded, App Host can import components like:
|
|
125
|
+
|
|
126
|
+
```js
|
|
127
|
+
import AmenityForm from "bookingUIApp/AmenityForm";
|
|
128
|
+
import RoomCategoryForm from "bookingUIApp/RoomCategoryForm";
|
|
129
|
+
import ReservationForm from "bookingUIApp/ReservationForm";
|
|
130
|
+
```
|
|
131
|
+
## Folder Structure (App Host)
|
|
132
|
+
```js
|
|
133
|
+
App_Host/
|
|
134
|
+
├── src/
|
|
135
|
+
│ ├── bookingModule/
|
|
136
|
+
│ │ └── components/
|
|
137
|
+
│ │ ├── AmenityForm.tsx
|
|
138
|
+
│ │ ├── CreateRoomForm.tsx
|
|
139
|
+
│ │ ├── ExtraRequirementForm.tsx
|
|
140
|
+
│ │ ├── ReservationForm.tsx
|
|
141
|
+
│ │ └── RoomCategoryForm.tsx
|
|
142
|
+
│ ├── main.tsx
|
|
143
|
+
│ └── App.tsx
|
|
144
|
+
├── vite.config.ts
|
|
145
|
+
└── package.json
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## TypeScript Module Declarations
|
|
149
|
+
|
|
150
|
+
App Host includes declarations so TypeScript recognizes remote imports:
|
|
151
|
+
|
|
152
|
+
```js
|
|
153
|
+
declare module "bookingUIApp/AmenityForm";
|
|
154
|
+
declare module "bookingUIApp/RoomCategoryForm";
|
|
155
|
+
declare module "bookingUIApp/ExtraRequirementForm";
|
|
156
|
+
declare module "bookingUIApp/CreateRoomForm";
|
|
157
|
+
declare module "bookingUIApp/ReservationForm";
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Deployment (CDK)
|
|
161
|
+
|
|
162
|
+
1) Deploy All Stacks
|
|
163
|
+
|
|
164
|
+
```js
|
|
165
|
+
npm run deploy-all -- --env=hmsuat --profile=uattwo
|
|
166
|
+
npm run deploy-all -- --env=prod --profile=vekasa
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Deploy Specific Stack
|
|
170
|
+
```js
|
|
171
|
+
npm run deploy-all -- --env=hmsuat --profile=uattwo --stack=api
|
|
172
|
+
npm run deploy-all -- --env=hmsuat --profile=uattwo --stack=bucket
|
|
173
|
+
npm run deploy-all -- --env=hmsuat --profile=uattwo --stack=userPool
|
|
174
|
+
npm run deploy-all -- --env=hmsuat --profile=uattwo --stack=idPool
|
|
175
|
+
npm run deploy-all -- --env=hmsuat --profile=uattwo --stack=pipeline
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Final Notes
|
|
179
|
+
|
|
180
|
+
1) App Host loads remote components dynamically using federation
|
|
181
|
+
2) Remote micro UIs must expose federated modules
|
|
182
|
+
3) .env controls which URL App Host loads for each remote
|
|
183
|
+
4) Requires both host + remote to run in dev mode for testing
|
|
184
|
+
|