opticore-api-gateway 1.0.1 → 1.0.2
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/package.json +1 -1
- package/scripts/postinstall.cjs +22 -4
package/package.json
CHANGED
package/scripts/postinstall.cjs
CHANGED
|
@@ -110,13 +110,31 @@ if (lastImportIndex !== -1) {
|
|
|
110
110
|
serverContent.slice(insertAfter);
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
// Replace registerRouter() with gateway.getOpticoreRoutes()
|
|
113
|
+
// Replace registerRouter(...) with gateway.getOpticoreRoutes(), preserving any
|
|
114
|
+
// extra routes passed in (e.g. registerRouter([createProfilerRouter(profiler)])
|
|
115
|
+
// — real generated projects call it with the profiler router, never bare
|
|
116
|
+
// registerRouter()) by spreading them alongside the gateway's own routes.
|
|
117
|
+
let callSiteReplaced = false;
|
|
114
118
|
serverContent = serverContent.replace(
|
|
115
|
-
/registerRouter\(\)
|
|
116
|
-
|
|
119
|
+
/registerRouter\(\s*(\[[^\]]*\])?\s*\)/,
|
|
120
|
+
(_match, extrasArrayLiteral) => {
|
|
121
|
+
callSiteReplaced = true;
|
|
122
|
+
if (extrasArrayLiteral) {
|
|
123
|
+
const extras = extrasArrayLiteral.slice(1, -1).trim();
|
|
124
|
+
return `[...gateway.getOpticoreRoutes(), ${extras}]`;
|
|
125
|
+
}
|
|
126
|
+
return 'gateway.getOpticoreRoutes()';
|
|
127
|
+
}
|
|
117
128
|
);
|
|
118
129
|
|
|
119
|
-
|
|
130
|
+
if (!callSiteReplaced) {
|
|
131
|
+
console.warn('[opticore-api-gateway] Could not find a registerRouter(...) call in src/bootstrap/server/webApp.server.ts — leaving the file untouched. Wire the gateway in manually, see the README\'s "Integration with opticore-webapp" section.');
|
|
132
|
+
process.exit(0);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Only safe to drop the registerRouter import now that its only call site
|
|
136
|
+
// was actually replaced above — removing it unconditionally previously left
|
|
137
|
+
// a dangling reference to registerRouter() when the call had arguments.
|
|
120
138
|
serverContent = serverContent.replace(
|
|
121
139
|
/^import\s*\{[^}]*registerRouter[^}]*\}\s*from\s*["'][^"']+["'];\s*\n?/m,
|
|
122
140
|
''
|