mango-cms 0.3.36 → 0.3.37

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/cli.js CHANGED
@@ -537,6 +537,20 @@ async function detectWebServer() {
537
537
  }
538
538
  }
539
539
 
540
+ // Deploy-identity key for pm2 process names and web server config filenames.
541
+ // Defaults to `database` for backward compatibility (matches every existing
542
+ // deployed site today), but `database` is meant to be safely shareable across
543
+ // projects (e.g. a multi-tenant setup), while deploy identity must be unique
544
+ // per project on a given box. Set "deployId" in settings.json to override
545
+ // when a project intentionally shares its database with another deployed
546
+ // project — otherwise `mango deploy`/`mango launch` will silently skip
547
+ // creating a web server config for the second project (path already exists)
548
+ // and reload the FIRST project's live pm2 processes instead of starting its
549
+ // own (HAP-1990).
550
+ function deployId(settings) {
551
+ return (settings.deployId || settings.database).toLowerCase();
552
+ }
553
+
540
554
  // Helper function to generate nginx config
541
555
  function generateNginxConfig(settings, buildPath, deployUi = false) {
542
556
  const domain = settings.mangoDomain;
@@ -735,8 +749,8 @@ async function configureWebServer(settings, buildPath, deployUi = false) {
735
749
  generateApacheConfig(settings, buildPath, deployUi);
736
750
 
737
751
  const configPath = webServer === 'nginx' ?
738
- `/etc/nginx/sites-available/${settings.database.toLowerCase()}` :
739
- `/etc/apache2/sites-available/${settings.database.toLowerCase()}.conf`;
752
+ `/etc/nginx/sites-available/${deployId(settings)}` :
753
+ `/etc/apache2/sites-available/${deployId(settings)}.conf`;
740
754
 
741
755
  try {
742
756
  // Check if config already exists
@@ -749,7 +763,7 @@ async function configureWebServer(settings, buildPath, deployUi = false) {
749
763
 
750
764
  if (webServer === 'nginx') {
751
765
  // Create symlink if it doesn't exist
752
- const enabledPath = `/etc/nginx/sites-enabled/${settings.database.toLowerCase()}`;
766
+ const enabledPath = `/etc/nginx/sites-enabled/${deployId(settings)}`;
753
767
  if (!fs.existsSync(enabledPath)) {
754
768
  execSync(`sudo ln -s ${configPath} ${enabledPath}`);
755
769
  }
@@ -757,7 +771,7 @@ async function configureWebServer(settings, buildPath, deployUi = false) {
757
771
  execSync('sudo systemctl reload nginx');
758
772
  } else {
759
773
  // Enable apache site
760
- execSync(`sudo a2ensite ${settings.database.toLowerCase()}`);
774
+ execSync(`sudo a2ensite ${deployId(settings)}`);
761
775
  execSync('sudo systemctl reload apache2');
762
776
  }
763
777
  console.log(`${webServer} configuration has been updated and service reloaded`);
@@ -782,8 +796,8 @@ async function checkPM2() {
782
796
 
783
797
  // Helper function to manage PM2 process
784
798
  async function managePM2Process(settings) {
785
- const processName = `${settings.database.toLowerCase()}-mango`;
786
- const name = settings.database.toLowerCase()
799
+ const processName = `${deployId(settings)}-mango`;
800
+ const name = deployId(settings)
787
801
 
788
802
  try {
789
803
  // Check if process exists
@@ -825,7 +839,7 @@ async function manageUiPM2Process(settings, mangoCmsRoot, userProjectRoot) {
825
839
 
826
840
  const { dir: uiDir, ejected } = resolveUiDir(mangoCmsRoot, userProjectRoot);
827
841
  const uiPort = settings.uiPort || 3001;
828
- const processName = `${settings.database.toLowerCase()}-ui`;
842
+ const processName = `${deployId(settings)}-ui`;
829
843
 
830
844
  // Install deps + build the Nuxt app (reads this project's mango/config).
831
845
  if (!fs.existsSync(path.join(uiDir, 'node_modules'))) {
@@ -54,6 +54,19 @@ let appPlaceholder = '<!--SSR-->'
54
54
 
55
55
  let serve = async function (req, res) {
56
56
 
57
+ // Check for a short url redirect
58
+ let shortUrl = req.path.split('/').slice(1).join('/').split('?')[0]
59
+ if (shortUrl) {
60
+ let redirect = (await axios.get(`http://localhost:${settings.port}/shortUrls/?search={"short":"${shortUrl}"}`))?.data?.response?.[0]
61
+ if (redirect?.target) {
62
+ let target = redirect.target.includes('http') ? redirect.target : `https://${settings.siteDomain}/${redirect.target}`
63
+ let redirectUrl = redirect.referralSource ? `${target}?referral=${redirect.referralSource}&referralType=Page&utm_source=${redirect.referralSource}` : target
64
+ // Increment the visit count
65
+ await axios.put(`http://localhost:${settings.port}/shortUrls/${redirect.id}`, { visits: redirect.visits + 1 })
66
+ return res.redirect(redirectUrl)
67
+ }
68
+ }
69
+
57
70
  let index = fs.readFileSync('./index.html', 'utf8')
58
71
 
59
72
  // Cookies
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mango-cms",
3
- "version": "0.3.36",
3
+ "version": "0.3.37",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "exports": {