小编edo*_*rdr的帖子

如何在 gatsby-config.js 中使用 AWS Amplify 环境变量?

我正在用 GatsbyJS 构建一个应用程序。我在 gatsby-config.js 中使用环境变量。通过使用 .env.* 文件,GatsbyJS 应用程序在本地构建得很好。但是,当从 AWS Amplify 构建时,它会抱怨从环境变量中检索到的值无效。事实上,似乎process.env.MY_VAR在 gatsby-config.js 内部使用时,检索到的值是加密的(根据 AWSAmplify 文档)。

我尝试硬编码 env 的值。var 以确认加密是问题所在。我得到的错误是: TypeError [ERR_INVALID_URL]: Invalid URL: 6fbaeed85a68.

这清楚地表明,从检索到的值process.env.HOSTNAME6fbaeed85a68,而不是我在AWS中扩增网络的接口提供的实际价值。

下面是我的 gatsby-js.config:

const path = require(`path`);
const queries = require('./src/utils/algolia');
const feedOptions = require('./src/utils/feed');
require('dotenv').config({
  path: `.env.${process.env.NODE_ENV}`,
});

module.exports = {
  siteMetadata: {
    siteUrl: new URL(process.env.HOSTNAME).href,
    title: `APP_TITLE`,
  },
  plugins: [
    {
      resolve: `gatsby-source-kentico-cloud`,
      options: {
        deliveryClientConfig: {
          projectId: process.env.KENTICO_PROJECT_ID,
        },
        languageCodenames: process.env.KENTICO_LANGUAGES.split(';'),
      },
    },
    {
      resolve: `gatsby-plugin-algolia`,
      options: …
Run Code Online (Sandbox Code Playgroud)

encryption config environment-variables gatsby aws-amplify

6
推荐指数
1
解决办法
1256
查看次数