medusajs / b2b-starter-medusa

Official Medusa B2B Starter template. Features common B2B ecommerce requirements and can be easily adapted and extended.
https://dub.sh/medusa-b2b-starter
MIT License
141 stars 42 forks source link

Error: self-signed certificate in certificate chain #94

Closed MCode-Team closed 1 week ago

MCode-Team commented 1 week ago

I can't connect rds database digitalocean

medusa-config.js

const { QUOTE_MODULE } = require("./src/modules/quote"); const { loadEnv, defineConfig, Modules } = require("@medusajs/framework/utils");

loadEnv(process.env.NODE_ENV || 'development', process.cwd())

const fs = require('fs'); const path = require('path');

module.exports = defineConfig({ projectConfig: { databaseUrl: process.env.DATABASE_URL, databaseOptions: { ssl: process.env.NODE_ENV === 'production' ? { rejectUnauthorized: true, ca: fs.readFileSync(path.join(__dirname, process.env.DATABASE_SSL_CERT)), } : { rejectUnauthorized: false, }, }, http: { storeCors: process.env.STORE_CORS, adminCors: process.env.ADMIN_CORS, authCors: process.env.AUTH_CORS, jwtSecret: process.env.JWT_SECRET || "supersecret", cookieSecret: process.env.COOKIE_SECRET || "supersecret", }, }, modules: { companyModuleService: { resolve: "./modules/company", },

  resolve: "./modules/quote",
},
[Modules.CACHE]: {
  resolve: "@medusajs/medusa/cache-inmemory",
},
[Modules.WORKFLOW_ENGINE]: {
  resolve: "@medusajs/medusa/workflow-engine-inmemory",
},

}, });

1731780648885

riqwan commented 1 week ago

Hey @MCode-Team, can you share what your DATABASE_URL looks like? do redact the auth credentials before you do

MCode-Team commented 1 week ago

Hey @MCode-Team, can you share what your DATABASE_URL looks like? do redact the auth credentials before you do

Hey @riqwan , I can now connect to RDS database on DigitalOcean. by setting

Windows

set NODE_TLS_REJECT_UNAUTHORIZED=0

Linux/Mac

export NODE_TLS_REJECT_UNAUTHORIZED=0

// Set this at the very beginning of your application process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';

Share Full Code in file #medusa-config.js // Set this at the very beginning of your application process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';

// Your existing code follows const { QUOTE_MODULE } = require("./src/modules/quote"); const { loadEnv, defineConfig, Modules } = require("@medusajs/framework/utils");

loadEnv(process.env.NODE_ENV || 'development', process.cwd())

const fs = require('fs'); const path = require('path');

module.exports = defineConfig({ projectConfig: { databaseUrl: process.env.DATABASE_URL, databaseOptions: { ssl: { rejectUnauthorized: process.env.NODE_ENV === 'production' ? true : false, // Allow self-signed in development ca: process.env.DATABASE_SSL_CERT ? fs.existsSync(path.join(dirname, process.env.DATABASE_SSL_CERT)) ? fs.readFileSync(path.join(dirname, process.env.DATABASE_SSL_CERT)) : undefined : undefined, // Handle missing file }, }, http: { storeCors: process.env.STORE_CORS, adminCors: process.env.ADMIN_CORS, authCors: process.env.AUTH_CORS, jwtSecret: process.env.JWT_SECRET || "supersecret", cookieSecret: process.env.COOKIE_SECRET || "supersecret", }, }, modules: { companyModuleService: { resolve: "./modules/company", },

  resolve: "./modules/quote",
},
[Modules.CACHE]: {
  resolve: "@medusajs/medusa/cache-inmemory",
},
[Modules.WORKFLOW_ENGINE]: {
  resolve: "@medusajs/medusa/workflow-engine-inmemory",
},

}, });

riqwan commented 1 week ago

Sounds good!

To make it work with the config, what you need is actually this (I just noticed your option names are wrong):

projectConfig: {
  databaseUrl: `postgres://test:test@test:5432/test?sslmode=require`,
  databaseDriverOptions: {
    connection: {
      ssl: {
        rejectUnauthorized: true,
        ca: fs.existsSync(
          path.join(__dirname, process.env.DATABASE_SSL_CERT)
        ),
      },
    },
  },

Feel free to reopen if you come across more issues! 🤞🏻