@whoz-oss/coday-web 0.0.0-workstream-forge.3
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/LICENSE +21 -0
- package/README.md +157 -0
- package/index.js +91 -0
- package/package.json +20 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Biznet.io
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# Coday Web Package
|
|
2
|
+
|
|
3
|
+
This package provides the web interface launcher for Coday, bundling both the client (Angular app) and server components into a single executable package.
|
|
4
|
+
|
|
5
|
+
## Architecture
|
|
6
|
+
|
|
7
|
+
The web package acts as a thin orchestration layer:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
┌─────────────────────────────────────────┐
|
|
11
|
+
│ coday-web (index.js) │
|
|
12
|
+
│ ┌───────────────────────────────────┐ │
|
|
13
|
+
│ │ 1. Resolve client package path │ │
|
|
14
|
+
│ │ 2. Set CODAY_CLIENT_PATH env var │ │
|
|
15
|
+
│ │ 3. Import and run server │ │
|
|
16
|
+
│ └───────────────────────────────────┘ │
|
|
17
|
+
└─────────────────────────────────────────┘
|
|
18
|
+
│
|
|
19
|
+
┌───────────┴───────────┐
|
|
20
|
+
▼ ▼
|
|
21
|
+
┌──────────────┐ ┌──────────────┐
|
|
22
|
+
│ coday-server │ │ coday-client │
|
|
23
|
+
│ (Express) │───────▶│ (Angular) │
|
|
24
|
+
└──────────────┘ └──────────────┘
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage Modes
|
|
28
|
+
|
|
29
|
+
### Production Mode (Published Package)
|
|
30
|
+
|
|
31
|
+
Use the published npm package via npx:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# Using the published package
|
|
35
|
+
pnpm web
|
|
36
|
+
|
|
37
|
+
# Or directly with npx
|
|
38
|
+
npx @whoz-oss/coday-web --no_auth
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
In production mode:
|
|
42
|
+
- The web launcher resolves the client package from node_modules
|
|
43
|
+
- Server serves pre-built static files from the client package
|
|
44
|
+
- Single process handles both server and client
|
|
45
|
+
|
|
46
|
+
### Development Mode (Local Sources)
|
|
47
|
+
|
|
48
|
+
For development with live reload and local sources:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# Start both client and server in development mode
|
|
52
|
+
pnpm web:dev
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
This command:
|
|
56
|
+
- Starts the Angular dev server on port 4200 (with HMR)
|
|
57
|
+
- Starts the Express server on port 4100 (with tsx watch)
|
|
58
|
+
- Server proxies non-API requests to Angular dev server
|
|
59
|
+
- Changes to client or server code trigger automatic reloads
|
|
60
|
+
|
|
61
|
+
**How it works in dev mode:**
|
|
62
|
+
1. Client runs with Angular CLI dev server (localhost:4200)
|
|
63
|
+
2. Server runs with tsx watch (localhost:4100)
|
|
64
|
+
3. Server detects `BUILD_ENV=development` and proxies to Angular
|
|
65
|
+
4. API routes (e.g., `/api/*`) are handled by the server
|
|
66
|
+
5. All other routes are proxied to Angular for client-side routing
|
|
67
|
+
|
|
68
|
+
## Development Workflow
|
|
69
|
+
|
|
70
|
+
### Running Individual Services
|
|
71
|
+
|
|
72
|
+
You can also run services separately for debugging:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
# Run only the client (Angular dev server)
|
|
76
|
+
pnpm client
|
|
77
|
+
|
|
78
|
+
# Run only the server (Express with tsx watch)
|
|
79
|
+
pnpm server
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Building for Production
|
|
83
|
+
|
|
84
|
+
The web package depends on built client and server packages:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# Build all packages
|
|
88
|
+
pnpm nx run-many --target=build --projects=client,server,web
|
|
89
|
+
|
|
90
|
+
# Or build everything
|
|
91
|
+
pnpm nx run-many --target=build --all
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Testing Changes
|
|
95
|
+
|
|
96
|
+
When making changes to the web launcher:
|
|
97
|
+
|
|
98
|
+
1. Modify `apps/web/index.js`
|
|
99
|
+
2. Test with local server: `node apps/web/index.js --no_auth`
|
|
100
|
+
3. Verify client resolution works correctly
|
|
101
|
+
4. Check that server starts and serves the client
|
|
102
|
+
|
|
103
|
+
## Environment Variables
|
|
104
|
+
|
|
105
|
+
- `CODAY_CLIENT_PATH`: Set by the web launcher to tell server where client files are
|
|
106
|
+
- `BUILD_ENV`: Set to `development` by server's serve target for dev mode
|
|
107
|
+
- `PORT`: Override default server port (default: 3000 production, 4100 dev)
|
|
108
|
+
|
|
109
|
+
## Package Dependencies
|
|
110
|
+
|
|
111
|
+
```json
|
|
112
|
+
{
|
|
113
|
+
"@whoz-oss/coday-client": "workspace:*",
|
|
114
|
+
"@whoz-oss/coday-server": "workspace:*"
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
These use workspace protocol in development and resolve to specific versions when published.
|
|
119
|
+
|
|
120
|
+
## Troubleshooting
|
|
121
|
+
|
|
122
|
+
### "Could not resolve @whoz-oss/coday-client package"
|
|
123
|
+
|
|
124
|
+
This means the client package isn't built or installed:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
# In development
|
|
128
|
+
pnpm install
|
|
129
|
+
pnpm nx run client:build
|
|
130
|
+
|
|
131
|
+
# Or use the web:dev command which doesn't require builds
|
|
132
|
+
pnpm web:dev
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### "Failed to start server"
|
|
136
|
+
|
|
137
|
+
Check that all dependencies are installed:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
pnpm install
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Development mode not proxying correctly
|
|
144
|
+
|
|
145
|
+
Ensure both services are running:
|
|
146
|
+
1. Angular dev server should be on port 4200
|
|
147
|
+
2. Express server should be on port 4100
|
|
148
|
+
3. Access the app via http://localhost:4100
|
|
149
|
+
|
|
150
|
+
## Quick Reference
|
|
151
|
+
|
|
152
|
+
| Command | Mode | Ports | Use Case |
|
|
153
|
+
|---------|------|-------|----------|
|
|
154
|
+
| `pnpm web` | Production | 3000 | Testing published package |
|
|
155
|
+
| `pnpm web:dev` | Development | 4100→4200 | Active development |
|
|
156
|
+
| `pnpm client` | Development | 4200 | Client-only work |
|
|
157
|
+
| `pnpm server` | Development | 4100 | Server-only work |
|
package/index.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
3
|
+
import { dirname, resolve } from 'path';
|
|
4
|
+
import { existsSync } from 'fs';
|
|
5
|
+
import { createRequire } from 'module';
|
|
6
|
+
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = dirname(__filename);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Coday Web Launcher
|
|
12
|
+
*
|
|
13
|
+
* This script orchestrates the web interface by:
|
|
14
|
+
* 1. Resolving the client package location at runtime
|
|
15
|
+
* 2. Setting the client path for the server to use
|
|
16
|
+
* 3. Delegating execution to the server package
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// Create require function for resolving packages
|
|
20
|
+
const require = createRequire(import.meta.url);
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Resolve the client package location
|
|
24
|
+
*
|
|
25
|
+
* Tries multiple resolution strategies:
|
|
26
|
+
* 1. Standard node_modules resolution (production/npx)
|
|
27
|
+
* 2. Workspace protocol resolution (development)
|
|
28
|
+
* 3. Relative path fallback (monorepo development)
|
|
29
|
+
*/
|
|
30
|
+
function resolveClientPath() {
|
|
31
|
+
try {
|
|
32
|
+
// Try to resolve the client package using Node's module resolution
|
|
33
|
+
const clientPackagePath = require.resolve('@whoz-oss/coday-client/package.json');
|
|
34
|
+
const clientPath = dirname(clientPackagePath);
|
|
35
|
+
|
|
36
|
+
// Check if browser directory exists
|
|
37
|
+
const browserPath = resolve(clientPath, 'browser');
|
|
38
|
+
if (existsSync(browserPath)) {
|
|
39
|
+
return browserPath;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Fallback: browser might be at package root for published package
|
|
43
|
+
if (existsSync(resolve(clientPath, 'index.html'))) {
|
|
44
|
+
return clientPath;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
console.error('Client package found but browser directory is missing.');
|
|
48
|
+
console.error(`Checked paths: ${browserPath}, ${clientPath}`);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
// Fallback for monorepo development
|
|
52
|
+
const devClientPath = resolve(__dirname, '../../client/dist/browser');
|
|
53
|
+
if (existsSync(devClientPath)) {
|
|
54
|
+
console.log('Using development client build from monorepo');
|
|
55
|
+
return devClientPath;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
console.error('Could not resolve @whoz-oss/coday-client package.');
|
|
59
|
+
console.error('Please ensure dependencies are installed: pnpm install');
|
|
60
|
+
console.error('Error:', error.message);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Resolve and set the client path
|
|
66
|
+
const clientPath = resolveClientPath();
|
|
67
|
+
process.env.CODAY_CLIENT_PATH = clientPath;
|
|
68
|
+
|
|
69
|
+
console.log(`Coday Web: Using client files from ${clientPath}`);
|
|
70
|
+
|
|
71
|
+
// Import and run the server
|
|
72
|
+
// The server package exports its main module which starts the server
|
|
73
|
+
try {
|
|
74
|
+
// Try to resolve the server package
|
|
75
|
+
const serverPackagePath = require.resolve('@whoz-oss/coday-server/package.json');
|
|
76
|
+
const serverDir = dirname(serverPackagePath);
|
|
77
|
+
const serverMainPath = resolve(serverDir, 'server.js');
|
|
78
|
+
|
|
79
|
+
// Import the server module
|
|
80
|
+
// Convert Windows absolute path to file:// URL for ESM import
|
|
81
|
+
const serverModuleURL = pathToFileURL(serverMainPath).href;
|
|
82
|
+
import(serverModuleURL).catch((error) => {
|
|
83
|
+
console.error('Failed to start server:', error);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
});
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.error('Could not resolve @whoz-oss/coday-server package.');
|
|
88
|
+
console.error('Please ensure dependencies are installed: pnpm install');
|
|
89
|
+
console.error('Error:', error.message);
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@whoz-oss/coday-web",
|
|
3
|
+
"version": "0.0.0-workstream-forge.3",
|
|
4
|
+
"repository": "https://github.com/whoz-oss/coday",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"coday-web": "./index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"index.js",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@whoz-oss/coday-client": "0.0.0-workstream-forge.3",
|
|
15
|
+
"@whoz-oss/coday-server": "0.0.0-workstream-forge.3"
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
}
|
|
20
|
+
}
|