This commit is contained in:
2026-04-06 00:33:27 +07:00
parent 0f7e386e2a
commit 9f4370365a
4 changed files with 32 additions and 27 deletions

View File

@@ -287,7 +287,7 @@ bun install
```bash ```bash
# Start server với PM2 # Start server với PM2
pm2 start ecosystem.config.js --env production pm2 start ecosystem.config.cjs --env production
# Hoặc start trực tiếp # Hoặc start trực tiếp
pm2 start server.js --name "charging-station-mock" --interpreter bun pm2 start server.js --name "charging-station-mock" --interpreter bun
@@ -368,7 +368,7 @@ sudo certbot renew --dry-run
| Command | Mô tả | | Command | Mô tả |
|---------|-------| |---------|-------|
| `pm2 start ecosystem.config.js` | Start với config file | | `pm2 start ecosystem.config.cjs` | Start với config file |
| `pm2 start server.js --name app` | Start với tên custom | | `pm2 start server.js --name app` | Start với tên custom |
| `pm2 list` | Xem danh sách processes | | `pm2 list` | Xem danh sách processes |
| `pm2 logs [name]` | Xem logs | | `pm2 logs [name]` | Xem logs |
@@ -386,9 +386,9 @@ sudo certbot renew --dry-run
# Cách 1: Environment variable # Cách 1: Environment variable
PORT=3200 pm2 start server.js --name "charging-station-mock" --interpreter bun PORT=3200 pm2 start server.js --name "charging-station-mock" --interpreter bun
# Cách 2: Sửa ecosystem.config.js # Cách 2: Sửa ecosystem.config.cjs
# env_production: { PORT: 3200 } # env_production: { PORT: 3200 }
pm2 start ecosystem.config.js --env production pm2 start ecosystem.config.cjs --env production
``` ```
--- ---

21
ecosystem.config.cjs Normal file
View File

@@ -0,0 +1,21 @@
module.exports = {
apps: [
{
name: 'charging-station-mock',
script: 'server.js',
interpreter: 'bun',
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: '500M',
env: {
NODE_ENV: 'development',
PORT: 3100,
},
env_production: {
NODE_ENV: 'production',
PORT: 3100,
},
},
],
};

View File

@@ -1,21 +0,0 @@
module.exports = {
apps: [
{
name: 'charging-station-mock',
script: 'server.js',
interpreter: 'bun',
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: '500M',
env: {
NODE_ENV: 'development',
PORT: 3100,
},
env_production: {
NODE_ENV: 'production',
PORT: 3100,
},
},
],
};

1
ecosystem.config.js Symbolic link
View File

@@ -0,0 +1 @@
ecosystem.config.cjs

View File

@@ -1,13 +1,17 @@
import path from 'node:path'; import path from 'node:path';
import { fileURLToPath } from 'node:url';
import jsonServer from 'json-server'; import jsonServer from 'json-server';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const server = jsonServer.create(); const server = jsonServer.create();
const router = jsonServer.router(path.join(import.meta.dir, 'db.json')); const router = jsonServer.router(path.join(__dirname, 'db.json'));
// Serve static files từ folder public (images, etc.) // Serve static files từ folder public (images, etc.)
const middlewares = jsonServer.defaults({ const middlewares = jsonServer.defaults({
logger: true, logger: true,
static: path.join(import.meta.dir, 'public'), static: path.join(__dirname, 'public'),
}); });
const port = process.env.PORT || 3100; const port = process.env.PORT || 3100;