Is there a way to script in the `server.json` or t...
# cfml-general
p
Is there a way to script in the
server.json
or the
CFConfig.json
in commandbox to setup mappings, DSNs, and Packages rather than doing those manually in the CF Administrator afterwards? I'm trying to learn to use this tool and that would be a helpful thing to know. I did find this code for packages in Ortus books
Copy code
"scripts":{
        "onServerInitialInstall":"cfpm install websocket"
    }
Do I just list the packages with a comma separating them?
d
Yes, look at cfconfig module for DSNs, and mappings can be done in server.json
for cfconfig, in server.json you will need this:
Copy code
"cfconfig":{
   "file":"server.cfconfig.json"
},
and in the server.cfconfig.json you datasources:
Copy code
"datasources": {
        "intra": {
            "class": "com.microsoft.sqlserver.jdbc.SQLServerDriver",
            "custom": {
                "DATABASENAME": "intra",
                "SelectMethod": "direct",
                "trustServerCertificate": "true"
            },
            "database": "intra",
            "dbdriver": "MSSQL",
            "dsn": "jdbc:sqlserver://${TP_DB_HOST}:1433",
            "password": "${TP_DB_PASSWORD}",
            "username": "${TP_DB_USER}"
        }
}
and to protect your password and other sensitive info
${TP_DB_PASSWORD}
use the module "commandbox-dotenv"
for mappings, in server.json use :
Copy code
"aliases":{
            "/images":"main_app/includes/images"
        }
but check the docs here to make sure this is what you need: https://commandbox.ortusbooks.com/embedded-server/configuring-your-server/aliases
b
Note, the aliases in server.json are primarily web aliases, not necessarily CF mappings as defined in the admin. Whether or not the CF engine "sees" them, depends on whether you're using Lucee or Adobe. CFConfig tracks CF mappings