Using strapi 1.5.4
.
Is it possible to configure strapi with environment variables? If not, how do you configure strapi without committing/exposing your database credentials and other secrets?
module.exports = {
"orm": {
"adapters": {
"disk": "sails-disk",
"mysql": "sails-mysql"
},
"defaultConnection": "default",
"connections": {
"default": {
"adapter": "disk",
"filePath": ".tmp/",
"fileName": "default.db",
"migrate": "alter"
},
"permanent": {
"adapter": "mysql",
"user": process.env.DB_USER,
"password": process.env.DB_PASSWORD,
"migrate": "alter"
}
}
}
};
Looks like the only way is to use a hook.
In my server.js
file (I would move the config into it's own file and clean this up)
const orm = {
"adapters": {
"disk": "sails-disk",
"mysql": "sails-mysql"
},
"defaultConnection": "default",
"connections": {
"default": {
"adapter": "disk",
"filePath": ".tmp/",
"fileName": "default.db",
"migrate": "alter"
},
"permanent": {
"adapter": "mysql",
"user": process.env.DB_USER || 'root',
"password": process.env.DB_PASSWORD || 'password',
"database": process.env.DB_NAME || 'test',
"host": "127.0.0.1",
"migrate": "alter"
}
}
};
(function () {
const strapi = require('strapi');
// Use a hook to override the config
strapi.on('hook:_config:loaded', () => {
strapi.config.orm = orm;
});
strapi.start();
})();