Help with stripe API keys not working when deploying app
I am deploying my application that has a stripe checkout integration (with live API keys).
It works perfectly with local host but it is not working when I deploy it, it says there is no stripe API keys.
import Stripe from 'stripe';
console.log('stripeapi',process.env.STRIPE_SECRET_KEY);
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
The above is how I use it, and I am defining it in the railway dashboard as other environment variables are defined,
Use an official Node.js runtime as the base image
FROM node:16
Set the working directory in the container to /app
WORKDIR /app
Copy package.json and package-lock.json to the working directory
COPY package*.json ./
Install any needed packages specified in package.json
RUN npm install
Copy the rest of the application to the working directory
COPY . .
RUN npm run build
RUN printenv
RUN echo "STRIPE_API_KEY: $STRIPE_API_KEY"
CMD echo "STRIPE_API_KEY: $STRIPE_API_KEY"
Make port 3000 available to the world outside this container
EXPOSE 3000
Define the command to run your app using CMD which defines your runtime
CMD [ "npm", "start" ]
CMD ["sh", "-c", "echo 'STRIPE_API_KEY: $STRIPE_API_KEY' && npm start"]
This is my docker file
Solution:Jump to solution
```dockerfile
Use an official Node.js runtime as the base image
FROM node:16
ARG DATABASE_URL...
20 Replies
Project ID:
N/A
I don't think service variables are available during build
Yeah that's not the problem
I might be misremembering though
Problem is that when app is deployed
It is not able to access stripe API keys for some reason
And I do have them defined here
oh, I was mentioning it since you're trying to log them during build
Yeah I realized that
they are
Oh okay
re-send your dockerfile, but please enclose it in triple backticks
""""""
'''
Use an official Node.js runtime as the base image
FROM node:16
Set the working directory in the container to /app
WORKDIR /app
Copy package.json and package-lock.json to the working directory
COPY package*.json ./
Install any needed packages specified in package.json
RUN npm install
Copy the rest of the application to the working directory
COPY . .
RUN npm run build
CMD ["npm", "start"]
'''
backticks please
can you list all the environment variables you need during build?
DATABASE_URL
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY
STRIPE_SECRET_KEY
Solution
Thank you Brody
You're the goat
no problem!