Hi!
Ever since I first found out about this project I’ve wanted to version control my config.js so I can share it with others and easily make backups. I’ve looked but haven’t found any easy way to do this while still keeping all my API keys secret since I’m running Magic Mirror server only in a docker container (with an Android tablet with Fully Kiosk Browser as the client).
However, I’ve found a way using the query parameters of the URL which works in my scenario, please let me know if you get it to work for you as well.
In the top of your config.js, add:
const urlParams = new URLSearchParams(location.search);
const secrets = Object.fromEntries(urlParams);
Then further down where the secret is to be used, just add:
modules: [
{
module: "currentweather",
position: "top_right",
config: {
location: "Amsterdam,Netherlands",
appid: secrets.weatherApiKey
}
}
]
Then, wherever you start your Magic Mirror, change the URL so it’s something like:
http://192.168.1.10:8123/?weatherApiKey=abcdefg123456&otheKey=secretkey123
Now if you only have a few secrets then managing the URL shouldn’t be that hard. However if you do have plenty of keys and if you are able to run PHP then try out this PHP script to make managing the keys more easily:
< ?php // Remove space
$ip = '192.168.1.10';
$port = 8123;
$secrets = array(
'weatherApiKey' => '123456',
'calendarApiKey' => 'abcdefg'
'metroApiKey' => 'abc123',
);
$url = "http://$ip:$port/?" . http_build_query($secrets);
header("Location: $url");
exit();
?>
Don’t forget to point whatever client you’re using to this PHP script instead.
Let me know what you think or if you have any suggestions on improvements! :)