Files
cloudron-box/src/constants.js
T
Girish Ramakrishnan 96dc79cfe6 Migrate codebase from CommonJS to ES Modules
- Convert all require()/module.exports to import/export across 260+ files
- Add "type": "module" to package.json to enable ESM by default
- Add migrations/package.json with "type": "commonjs" to keep db-migrate compatible
- Convert eslint.config.js to ESM with sourceType: "module"
- Replace __dirname/__filename with import.meta.dirname/import.meta.filename
- Replace require.main === module with process.argv[1] === import.meta.filename
- Remove 'use strict' directives (implicit in ESM)
- Convert dynamic require() in switch statements to static import lookup maps
  (dns.js, domains.js, backupformats.js, backupsites.js, network.js)
- Extract self-referencing exports.CONSTANT patterns into standalone const
  declarations (apps.js, services.js, locks.js, users.js, mail.js, etc.)
- Lazify SERVICES object in services.js to avoid circular dependency TDZ issues
- Add clearMailQueue() to mailer.js for ESM-safe queue clearing in tests
- Add _setMockApp() to ldapserver.js for ESM-safe test mocking
- Add _setMockResolve() wrapper to dig.js for ESM-safe DNS mocking in tests
- Convert backupupload.js to use dynamic imports so --check exits before
  loading the module graph (which requires BOX_ENV)
- Update check-install to use ESM import for infra_version.js
- Convert scripts/ (hotfix, release, remote_hotfix.js, find-unused-translations)
- All 1315 tests passing

Migration stats (AI-assisted using Cursor with Claude):
- Wall clock time: ~3-4 hours
- Assistant completions: ~80-100
- Estimated token usage: ~1-2M tokens

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-14 15:11:45 +01:00

94 lines
3.1 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
const CLOUDRON = process.env.BOX_ENV === 'cloudron',
TEST = process.env.BOX_ENV === 'test';
export default {
SMTP_SUBDOMAIN: 'smtp',
IMAP_SUBDOMAIN: 'imap',
// These are combined into one array because users and groups become mailboxes
RESERVED_NAMES: [
// Reserved usernames
// https://github.com/gogits/gogs/blob/52c8f691630548fe091d30bcfe8164545a05d3d5/models/repo.go#L393
// apps like wordpress, gogs don't like these
// postmaster is used in dovecot and haraka
'admin', 'no-reply', 'postmaster', 'mailer-daemon', 'root',
// Reserved groups
'admins', 'users' // ldap code uses 'users' pseudo group
],
DASHBOARD_SUBDOMAIN: 'my',
PORT: CLOUDRON ? 3000 : 5454,
GRAPHITE_PORT: 2003,
INTERNAL_SMTP_PORT: 2525, // this value comes from the mail container
AUTHWALL_PORT: 3001,
LDAP_PORT: 3002,
DOCKER_PROXY_PORT: 3003,
USER_DIRECTORY_LDAPS_PORT: 3004, // user directory LDAP with TLS rerouting in iptables, public port is 636
OIDC_PORT: 3005,
TURN_PORT: 3478, // tcp and udp
TURN_TLS_PORT: 5349, // tcp and udp
TURN_UDP_PORT_START: 50000,
TURN_UDP_PORT_END: 50100,
// docker IPs
DOCKER_IPv4_SUBNET: '172.18.0.0/16',
DOCKER_IPv4_RANGE: '172.18.0.0/20', // addresses are dynamically allocated within this range (172.18.0.0-172.18.15.255)
DOCKER_IPv4_GATEWAY: '172.18.0.1',
APPS_IPv4_START: '172.18.16.1', // after DOCKER_IPv4_RANGE
APPS_IPv4_END: '172.18.20.255',
DOCKER_IPv6_SUBNET: 'fd00:c107:d509::/64',
// these are hardcoded to allow connections from outside. this is not in "172.18.0.xx" since docker starts allocating from there
MYSQL_SERVICE_IPv4: '172.18.30.1',
POSTGRESQL_SERVICE_IPv4: '172.18.30.2',
MONGODB_SERVICE_IPv4: '172.18.30.3',
MAIL_SERVICE_IPv4: '172.18.30.4',
GRAPHITE_SERVICE_IPv4: '172.18.30.5',
SFTP_SERVICE_IPv4: '172.18.30.6',
NGINX_DEFAULT_CONFIG_FILE_NAME: 'default.conf',
DEFAULT_TOKEN_EXPIRATION_MSECS: 365 * 24 * 60 * 60 * 1000, // 1 year
DEFAULT_TOKEN_EXPIRATION_DAYS: 365,
DEFAULT_MEMORY_LIMIT: (256 * 1024 * 1024), // see also client.js
DEMO: fs.existsSync('/etc/cloudron/DEMO'),
DEMO_USERNAME: 'cloudron',
DEMO_BLOCKED_APPS: [
'org.jupyter.cloudronapp',
'com.github.cloudtorrent',
'net.alltubedownload.cloudronapp',
'com.adguard.home.cloudronapp',
'com.transmissionbt.cloudronapp',
'io.github.sickchill.cloudronapp',
'to.couchpota.cloudronapp',
'org.qbittorrent.cloudronapp'
],
DEMO_APP_LIMIT: 20,
PROXY_APP_APPSTORE_ID: 'io.cloudron.builtin.appproxy',
CRON_PATTERN_NEVER: 'never',
SNAPSHOT_INFO_FILENAME: 'snapshot-info.json',
CLOUDRON,
TEST,
PORT25_CHECK_SERVER: 'port25check.cloudron.io',
USER_DIRECTORY_LDAP_DN: 'cn=admin,ou=system,dc=cloudron',
FOOTER: '&copy; %YEAR% [Cloudron](https://cloudron.io)',
VERSION: process.env.BOX_ENV === 'cloudron' ? fs.readFileSync(path.join(import.meta.dirname, '../VERSION'), 'utf8').trim() : '8.0.0-test'
};