<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Unable to Access Environment Variables in Vue.js App on Cloudron]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I'm currently developing a Vue.js application and deploying it on Cloudron. I'm trying to access an environment variable (VUE_APP_DIRECTUS_TOKEN) in my Vue.js component, but it always returns undefined.</p>
<p dir="auto">Here's the relevant part of my code:</p>
<pre><code>methods: {
  async register() {
    try {
      await axios.post(
        'https://directus.example.com',
        {
          email: this.email,
          password: this.password,
          status: 'active'
        },
        {
          headers: {
            Authorization: `Bearer ${import.meta.env.VUE_APP_DIRECTUS_TOKEN}`
          }
        }
      )
      alert('Registration successful')
    } catch (error) {
      alert('Registration failed: ' + error.message)
    }
  }
}
</code></pre>
<p dir="auto">I've tried setting the environment variable in a .env file in the root of my project, and also in an <a href="http://env.sh" target="_blank" rel="noopener noreferrer nofollow ugc">env.sh</a> file in the /app/data/ directory as suggested by Cloudron's documentation. I've also tried using the export keyword. However, none of these methods seem to work.</p>
<p dir="auto">Here's how I've set the environment variable:</p>
<pre><code>export VUE_APP_DIRECTUS_TOKEN=my_token_here
</code></pre>
<p dir="auto">Sure, here's a draft for your forum question:</p>
<hr />
<p dir="auto"><strong>Title:</strong> Unable to Access Environment Variables in Vue.js App on Cloudron</p>
<p dir="auto"><strong>Body:</strong></p>
<p dir="auto">Hello,</p>
<p dir="auto">I'm currently developing a Vue.js application and deploying it on Cloudron. I'm trying to access an environment variable (<code>VUE_APP_DIRECTUS_TOKEN</code>) in my Vue.js component, but it always returns <code>undefined</code>.</p>
<p dir="auto">Here's the relevant part of my code:</p>
<pre><code class="language-vue">methods: {
  async register() {
    try {
      await axios.post(
        'https://wij.metaalkathedraal.nl/users',
        {
          email: this.email,
          password: this.password,
          status: 'active'
        },
        {
          headers: {
            Authorization: `Bearer ${import.meta.env.VUE_APP_DIRECTUS_TOKEN}`
          }
        }
      )
      alert('Registration successful')
    } catch (error) {
      alert('Registration failed: ' + error.message)
    }
  }
}
</code></pre>
<p dir="auto">I've tried setting the environment variable in a <code>.env</code> file in the root of my project, and also in an <code>env.sh</code> file in the <code>/app/data/</code> directory as suggested by Cloudron's documentation. I've also tried using the <code>export</code> keyword. However, none of these methods seem to work.</p>
<p dir="auto">Here's how I've set the environment variable:</p>
<pre><code class="language-bash">export VUE_APP_DIRECTUS_TOKEN=your_token_here
</code></pre>
<p dir="auto">I've made sure to restart the app after making changes to the environment variables.</p>
<p dir="auto">I'm able to hardcode the token directly into the code and it works, so the issue seems to be with loading the environment variable.</p>
<p dir="auto">Does anyone have any suggestions on how to correctly set and access environment variables in a Vue.js app on Cloudron?</p>
<p dir="auto">Thank you in advance for your help.</p>
]]></description><link>https://forum.cloudron.io/topic/11315/unable-to-access-environment-variables-in-vue-js-app-on-cloudron</link><generator>RSS for Node</generator><lastBuildDate>Thu, 12 Mar 2026 01:10:24 GMT</lastBuildDate><atom:link href="https://forum.cloudron.io/topic/11315.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 14 Mar 2024 23:14:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Unable to Access Environment Variables in Vue.js App on Cloudron on Tue, 19 Mar 2024 19:34:31 GMT]]></title><description><![CDATA[<p dir="auto">It is only created within the directus app instance. Different apps run isolated from one another on Cloudron. So if I understand you correctly, you are trying to build your own custom app next to directus? If so you need to set the source your own <code>/app/data/env.sh</code> with the export of the env var.</p>
]]></description><link>https://forum.cloudron.io/post/85281</link><guid isPermaLink="true">https://forum.cloudron.io/post/85281</guid><dc:creator><![CDATA[nebulon]]></dc:creator><pubDate>Tue, 19 Mar 2024 19:34:31 GMT</pubDate></item><item><title><![CDATA[Reply to Unable to Access Environment Variables in Vue.js App on Cloudron on Tue, 19 Mar 2024 10:20:40 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/nebulon" aria-label="Profile: nebulon">@<bdi>nebulon</bdi></a> Hi Nebulon, sorry for my late response. Busy week!</p>
<p dir="auto">When I look at the <a href="http://start.sh" target="_blank" rel="noopener noreferrer nofollow ugc">start.sh</a> file I see the following lines:</p>
<pre><code>if [[ ! -f /app/data/env.sh ]]; then
    sudo -u cloudron cat &gt; /app/data/env.sh &lt;&lt;EOF
export KEY="$(uuid -v4)"
export SECRET="$(pwgen -1 32)"
EOF
fi

cp /app/data/env.sh /run/directus/env.sh
[[ -f /app/data/env ]] &amp;&amp; cat /app/data/env &gt;&gt; /run/directus/env.sh

source /run/directus/env.sh
</code></pre>
<p dir="auto">So it looks like it's allready there?</p>
]]></description><link>https://forum.cloudron.io/post/85227</link><guid isPermaLink="true">https://forum.cloudron.io/post/85227</guid><dc:creator><![CDATA[webthingz]]></dc:creator><pubDate>Tue, 19 Mar 2024 10:20:40 GMT</pubDate></item><item><title><![CDATA[Reply to Unable to Access Environment Variables in Vue.js App on Cloudron on Fri, 15 Mar 2024 07:49:26 GMT]]></title><description><![CDATA[<p dir="auto">I guess this is more like a generic question not so much related to Directus. So environment variables are not exposed automatically from a <code>.env</code> file, you would need to <code>source /app/data/.env</code> in your <code>start.sh</code> script which should be the entry point <code>CMD [ "/app/code/start.sh" ]</code> in your <code>Dockerfile</code>.</p>
<p dir="auto">You can find more info at <a href="https://docs.cloudron.io/packaging/cheat-sheet/" target="_blank" rel="noopener noreferrer nofollow ugc">https://docs.cloudron.io/packaging/cheat-sheet/</a> with links to existing packages for inspiration.</p>
]]></description><link>https://forum.cloudron.io/post/85108</link><guid isPermaLink="true">https://forum.cloudron.io/post/85108</guid><dc:creator><![CDATA[nebulon]]></dc:creator><pubDate>Fri, 15 Mar 2024 07:49:26 GMT</pubDate></item></channel></rss>