Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: configure the plugin (Google API key) with an environment variable #12

Open
mickaeltr opened this issue Aug 8, 2024 · 0 comments

Comments

@mickaeltr
Copy link

Hello,
I think it would be a nice addition to be able to configure the plugin (Google API key) with an environment variable.
In the meantime, if it help others, I've worked around this with the following boostrap function:

import { Strapi } from "@strapi/strapi";
import { env } from "@strapi/utils";

const configKey = "GOOGLE_MAPS_API_KEY";

// Workaround to the "strapi-google-maps" plugin not being configurable with environment variables
export async function bootstrapGoogleMapsConfig(strapi: Strapi): Promise<void> {
  const googleMapsApiKey = env(configKey);
  if (!googleMapsApiKey) {
    throw new Error(`Missing ${configKey} in CMS env`);
  }
  const { changes } = await strapi.db.connection.raw(
    `UPDATE google_maps_configs
     SET google_maps_key = '${googleMapsApiKey}',
         updated_at      = CURRENT_TIMESTAMP`,
  );
  if (changes === 0) {
    await strapi.db.connection.raw(
      `INSERT INTO google_maps_configs(google_maps_key, created_at, updated_at)
       VALUES ('${googleMapsApiKey}', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)`,
    );
  }
}

Thanks for this plugin!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant