medusa-config.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. const dotenv = require('dotenv')
  2. let ENV_FILE_NAME = '';
  3. switch (process.env.NODE_ENV) {
  4. case 'production':
  5. ENV_FILE_NAME = '.env.production';
  6. break;
  7. case 'staging':
  8. ENV_FILE_NAME = '.env.staging';
  9. break;
  10. case 'test':
  11. ENV_FILE_NAME = '.env.test';
  12. break;
  13. case 'development':
  14. default:
  15. ENV_FILE_NAME = '.env';
  16. break;
  17. }
  18. try {
  19. dotenv.config({ path: process.cwd() + '/' + ENV_FILE_NAME });
  20. } catch (e) {
  21. }
  22. // CORS when consuming Medusa from admin
  23. const ADMIN_CORS = process.env.ADMIN_CORS || "http://localhost:7000,http://localhost:7001";
  24. // CORS to avoid issues when consuming Medusa from a client
  25. const STORE_CORS = process.env.STORE_CORS || "http://localhost:8000";
  26. const DB_USERNAME = process.env.DB_USERNAME;
  27. const DB_PASSWORD = process.env.DB_PASSWORD;
  28. const DB_HOST = process.env.DB_HOST;
  29. const DB_PORT = process.env.DB_PORT;
  30. const DB_DATABASE = process.env.DB_DATABASE;
  31. const DATABASE_URL = `postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_DATABASE}`;
  32. // Medusa uses Redis, so this needs configuration as well
  33. const REDIS_URL = process.env.REDIS_URL || "redis://localhost:6379";
  34. // Stripe keys
  35. const STRIPE_API_KEY = process.env.STRIPE_API_KEY || "";
  36. const STRIPE_WEBHOOK_SECRET = process.env.STRIPE_WEBHOOK_SECRET || "";
  37. // This is the place to include plugins. See API documentation for a thorough guide on plugins.
  38. const plugins = [
  39. `medusa-fulfillment-manual`,
  40. `medusa-payment-manual`,
  41. // Uncomment to add Stripe support.
  42. // You can create a Stripe account via: https://stripe.com
  43. // {
  44. // resolve: `medusa-payment-stripe`,
  45. // options: {
  46. // api_key: STRIPE_API_KEY,
  47. // webhook_secret: STRIPE_WEBHOOK_SECRET,
  48. // },
  49. // },
  50. ];
  51. module.exports = {
  52. projectConfig: {
  53. redis_url: REDIS_URL,
  54. // For more production-like environment install PostgresQL
  55. database_url: DATABASE_URL,
  56. database_type: "postgres",
  57. store_cors: STORE_CORS,
  58. admin_cors: ADMIN_CORS,
  59. database_extra: { ssl: { rejectUnauthorized: false } }
  60. },
  61. plugins,
  62. };