@ifecodes/backend-template 1.1.6 → 1.1.7
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/bin/cli.js
CHANGED
|
@@ -371,9 +371,15 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
371
371
|
description: config.description || "",
|
|
372
372
|
private: true,
|
|
373
373
|
scripts: {
|
|
374
|
-
dev:
|
|
375
|
-
|
|
376
|
-
|
|
374
|
+
dev:
|
|
375
|
+
mode === "docker"
|
|
376
|
+
? "docker-compose up"
|
|
377
|
+
: "npx pm2 start pm2.config.js && npx pm2 logs",
|
|
378
|
+
stop: mode === "docker" ? "docker-compose down" : "npx pm2 kill",
|
|
379
|
+
restart:
|
|
380
|
+
mode === "docker"
|
|
381
|
+
? "docker-compose restart"
|
|
382
|
+
: "npx pm2 restart all && npx pm2 logs",
|
|
377
383
|
lint: 'eslint "services/**/*.{js,ts,tsx}" "shared/**/*.{js,ts,tsx}"',
|
|
378
384
|
format:
|
|
379
385
|
'prettier --write "services/**/*.{js,ts,json}" "shared/**/*.{js,ts,json}"',
|
|
@@ -390,6 +396,16 @@ if (isInMicroserviceProject || config.projectType === "microservice") {
|
|
|
390
396
|
"eslint-config-prettier": "^10.1.8",
|
|
391
397
|
},
|
|
392
398
|
};
|
|
399
|
+
|
|
400
|
+
// Add runtime dependencies for non-Docker (PM2) mode
|
|
401
|
+
if (mode !== "docker") {
|
|
402
|
+
rootPackageJson.dependencies = {
|
|
403
|
+
dotenv: "^17.2.3",
|
|
404
|
+
pm2: "^6.0.14",
|
|
405
|
+
"ts-node": "^10.9.2",
|
|
406
|
+
"tsconfig-paths": "^4.2.0",
|
|
407
|
+
};
|
|
408
|
+
}
|
|
393
409
|
fs.writeFileSync(
|
|
394
410
|
rootPackageJsonPath,
|
|
395
411
|
JSON.stringify(rootPackageJson, null, 2) + "\n",
|
|
@@ -89,11 +89,18 @@ export const generatePm2Config = (target, allServices) => {
|
|
|
89
89
|
return {
|
|
90
90
|
name: serviceName,
|
|
91
91
|
script: `./services/${serviceName}/src/server.ts`,
|
|
92
|
+
interpreter: "node",
|
|
93
|
+
node_args:
|
|
94
|
+
"-r ts-node/register/transpile-only -r tsconfig-paths/register",
|
|
95
|
+
watch: true,
|
|
96
|
+
ignore_watch: ["node_modules", ".git", "logs"],
|
|
97
|
+
watch_delay: 1000,
|
|
92
98
|
instances: 1,
|
|
93
99
|
exec_mode: "fork",
|
|
94
100
|
env: {
|
|
95
|
-
PORT: port
|
|
96
|
-
|
|
101
|
+
PORT: port,
|
|
102
|
+
TS_NODE_PROJECT: `services/${serviceName}/tsconfig.json`,
|
|
103
|
+
},
|
|
97
104
|
};
|
|
98
105
|
}),
|
|
99
106
|
};
|
package/package.json
CHANGED
|
@@ -10,13 +10,14 @@ export const generateGatewayRoutes = (services, mode = "docker") => {
|
|
|
10
10
|
// Docker: use container name with internal port 4000
|
|
11
11
|
// Non-docker: use localhost with mapped host port
|
|
12
12
|
const host = mode === "docker" ? service : "localhost";
|
|
13
|
-
|
|
13
|
+
// Build a placeholder that will render as ${SERVICE_PORT} in the generated code
|
|
14
|
+
const servicePortPlaceholder = "${" + servicePort + "}";
|
|
14
15
|
|
|
15
16
|
return `
|
|
16
17
|
// Proxy to ${service}
|
|
17
18
|
const ${servicePort} = ENV.${servicePort} || ${port}
|
|
18
19
|
app.use("/api", createProxyMiddleware({
|
|
19
|
-
target: \`http://${host}:${
|
|
20
|
+
target: \`http://${host}:${servicePortPlaceholder}/api\`,
|
|
20
21
|
changeOrigin: true,
|
|
21
22
|
on: {
|
|
22
23
|
error: (err, req, res) => {
|