MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    secrets.js

    Scheduled Pinned Locked Moved Unsolved Feature Requests
    10 Posts 5 Posters 3.7k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • cowboysdudeC Offline
      cowboysdude Module Developer @rak
      last edited by

      @rak Well you’d have to take that up with the developers… so far this is the system that they implemented and it’s worked well so far :) You could always modify the config.js yourself to do what you want.

      1 Reply Last reply Reply Quote 0
      • mrmidiM Offline
        mrmidi
        last edited by mrmidi

        @rak You may wish to use dotenv. You can either do this on a module level, or for your local install.

        https://www.npmjs.com/package/dotenv

        Here you would just make an .env file in your project root with something like:

        API_KEY=MySuperSecretApiKey1
        

        Then you should be able to update the config file with:

        var localConfig = require('dotenv').config();
        
        var config = {
        ...
           { ...
              apiKey = process.env.API_KEY,
           }
        

        Just make sure to add the .env file to .gitignore so it won’t get committed via git.

        1 Reply Last reply Reply Quote 0
        • R Offline
          rak
          last edited by

          @mrmidi Thank you very much. This goes into the desired direction.

          I have installed dotenv and added

          var localConfig = require('dotenv').config();
          

          If I do so starting the MM it shows missing config file.

          Any ideas?

          1 Reply Last reply Reply Quote 0
          • mrmidiM Offline
            mrmidi
            last edited by

            @rak This is most interesting :)

            I am actually working on testing this now. There is no real reason this should not have worked, but you are 100% right, it seems to tank the config.

            What’s really interesting is that I am tinkering around in the ./js/app.js file, and it’s actually not breaking when it’s being imported. The config file that comes in gets merged just fine and consoling it out, shows the correct dontenv getting replaced.

            This means somewhere else along the line, this code is breaking.

            Hopefully I can follow the config through the app and detect where that’s happening and post back ASAP.

            strawberry 3.141S 1 Reply Last reply Reply Quote 0
            • mrmidiM Offline
              mrmidi
              last edited by

              @rak OK, so after digging into this more, it looks like this won’t work without an update to the way the config.js file is loaded.

              Currently, it is being loaded two ways.

              1. As an exportable module that can be used via require() statements
              2. As vanilla javascript

              So the dotenv would have worked fine ( and DOES work fine ) when used in a module context. However, the vanilla JS cannot reference module data this way. The solution would be to dig more into the ./js/app.js and ./js/main.js files and look at how they are handling the loadConfig functions and see if there is not a way to tweak it for your purposes.

              Sadly, there is not much more I can think of to help with that without spending several hours tinkering around.

              1 Reply Last reply Reply Quote 0
              • strawberry 3.141S Offline
                strawberry 3.141 Project Sponsor Module Developer @mrmidi
                last edited by

                @mrmidi I’m pretty sure the problem is, that the config file gets loaded in the browser. The browser doesn’t have require, it’s a nodejs feature.

                https://github.com/MichMich/MagicMirror/search?q=CONFIG_FILE&unscoped_q=CONFIG_FILE

                Please create a github issue if you need help, so I can keep track

                1 Reply Last reply Reply Quote 0
                • Y Offline
                  Ybbet
                  last edited by

                  Hi!

                  I understand this issue. I use a gitlab private repository. I clone it in “magicmirror_config” in /home/pi/
                  And then I created a symlink im /home/pi/MagicMirror/config/ for my versioned config.js

                  And all my personalized files are in symlink where I need it.

                  That’s really easy and like that I can test on local device (my Mac) before put it on the raspberry Pi. :-)

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  • First post
                    Last post
                  Enjoying MagicMirror? Please consider a donation!
                  MagicMirror created by Michael Teeuw.
                  Forum managed by Sam, technical setup by Karsten.
                  This forum is using NodeBB as its core | Contributors
                  Contact | Privacy Policy