@hamak/smart-data-dico 1.0.1 → 1.0.4
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/backend/package.json
CHANGED
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
"test:coverage": "jest --coverage"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@hamak/filesystem-server-api": "^0.5.
|
|
17
|
-
"@hamak/filesystem-server-impl": "^0.5.
|
|
18
|
-
"@hamak/filesystem-server-spi": "^0.5.
|
|
19
|
-
"@hamak/shared-utils": "^0.5.
|
|
20
|
-
"@hamak/ui-remote-git-fs-backend": "
|
|
16
|
+
"@hamak/filesystem-server-api": "^0.5.2",
|
|
17
|
+
"@hamak/filesystem-server-impl": "^0.5.2",
|
|
18
|
+
"@hamak/filesystem-server-spi": "^0.5.2",
|
|
19
|
+
"@hamak/shared-utils": "^0.5.2",
|
|
20
|
+
"@hamak/ui-remote-git-fs-backend": "^0.5.2",
|
|
21
21
|
"@types/jsonwebtoken": "^9.0.9",
|
|
22
22
|
"cors": "^2.8.5",
|
|
23
23
|
"dotenv": "^16.3.1",
|
package/backend/src/server.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import express, { Request, Response } from 'express';
|
|
2
|
+
import fs from 'fs';
|
|
2
3
|
import path from 'path';
|
|
3
4
|
import cors from 'cors';
|
|
4
5
|
import dotenv from 'dotenv';
|
|
@@ -36,10 +37,12 @@ app.use((req: Request, res: Response, next) => {
|
|
|
36
37
|
|
|
37
38
|
app.use(express.json());
|
|
38
39
|
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
40
|
+
// API welcome route (only in dev — production serves frontend at /)
|
|
41
|
+
if (!config.isProduction) {
|
|
42
|
+
app.get('/', (req: Request, res: Response) => {
|
|
43
|
+
res.json({ message: 'Welcome to the Data Dictionary Management System API' });
|
|
44
|
+
});
|
|
45
|
+
}
|
|
43
46
|
|
|
44
47
|
// Health check endpoint
|
|
45
48
|
app.get('/health', (req: Request, res: Response) => {
|
|
@@ -104,8 +107,35 @@ mountFrameworkRoutes().catch((err) => {
|
|
|
104
107
|
});
|
|
105
108
|
|
|
106
109
|
|
|
107
|
-
//
|
|
108
|
-
|
|
110
|
+
// Serve frontend static files in production (BEFORE error handler)
|
|
111
|
+
if (config.isProduction) {
|
|
112
|
+
// Check multiple possible frontend dist locations
|
|
113
|
+
const candidates = [
|
|
114
|
+
path.join(process.cwd(), 'public'), // Docker (copied to public/)
|
|
115
|
+
path.join(process.cwd(), '..', 'frontend', 'dist'), // npm package / monorepo
|
|
116
|
+
path.join(process.cwd(), 'frontend', 'dist'), // alt layout
|
|
117
|
+
];
|
|
118
|
+
const publicDir = candidates.find(d => {
|
|
119
|
+
try { return fs.statSync(d).isDirectory(); } catch { return false; }
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
if (publicDir) {
|
|
123
|
+
app.use(express.static(publicDir));
|
|
124
|
+
// SPA fallback — only for navigation requests, not assets/API
|
|
125
|
+
app.get('*', (req, res, next) => {
|
|
126
|
+
if (req.path.startsWith('/api') || req.path.startsWith('/fs') || req.path.startsWith('/api-docs') || req.path.includes('.')) {
|
|
127
|
+
return next();
|
|
128
|
+
}
|
|
129
|
+
res.sendFile(path.join(publicDir, 'index.html'));
|
|
130
|
+
});
|
|
131
|
+
logger.info(`Serving frontend from ${publicDir}`);
|
|
132
|
+
} else {
|
|
133
|
+
logger.warn('Frontend dist not found. API-only mode.');
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Error handling middleware (after static files)
|
|
138
|
+
app.use((err: any, req: Request, res: Response, _next: any) => {
|
|
109
139
|
logger.error(`Unhandled error: ${err.message}`);
|
|
110
140
|
res.status(500).json({
|
|
111
141
|
message: 'Internal server error',
|
|
@@ -113,18 +143,6 @@ app.use((err: any, req: Request, res: Response, next: any) => {
|
|
|
113
143
|
});
|
|
114
144
|
});
|
|
115
145
|
|
|
116
|
-
// Serve frontend static files in production
|
|
117
|
-
if (config.isProduction) {
|
|
118
|
-
const publicDir = path.join(process.cwd(), 'public');
|
|
119
|
-
app.use(express.static(publicDir));
|
|
120
|
-
app.get('*', (req, res) => {
|
|
121
|
-
if (!req.path.startsWith('/api') && !req.path.startsWith('/fs') && !req.path.startsWith('/api-docs')) {
|
|
122
|
-
res.sendFile(path.join(publicDir, 'index.html'));
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
logger.info(`Serving frontend from ${publicDir}`);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
146
|
// Start server only when run directly (not when imported by tests)
|
|
129
147
|
const isMainModule = process.argv[1] && (
|
|
130
148
|
process.argv[1].endsWith('server.ts') || process.argv[1].endsWith('server.js')
|
package/bin/cli.js
CHANGED