Env vars not being loaded on CF Pages domain

I am deploying using Github Actions and therefore, I am uploading on CF Pages with cloudflare/[email protected] I have an issue because I have some environment variables in a .env file For some reason, when the deploy is done, the environment variables are not loaded on CF Pages domain I looked for an answer but found not solution I know we can manually add environment variables to a CF Pages project but I want to automate as much as possible I am creating a .env file when running the Github Action with the correct environment variables I get the correct values when running npm run build But when I look at the CF Pages domain, it does not log the correct values By: @Anthodpnt
1 Reply
Vero
VeroOP2y ago
This is what I have so far: name: Build & CF Pages Deploy on: push: branches: - deploy/staging - deploy/production jobs: deploy: runs-on: ubuntu-latest environment: ${{ github.ref == 'refs/heads/deploy/production' && 'production' || 'preview' }} steps: - name: Install Node.js uses: actions/setup-node@v3 with: node-version: 16.x.x - name: Checkout uses: actions/checkout@v3 - name: Cache node_modules uses: actions/cache@v3 with: path: node_modules key: ubuntu-latest-node-v16.x.x-deps-${{ hashFiles(format('{0}{1}', github.workspace, '/package-lock.json')) }} - name: Extract Branch Name uses: nelonoel/[email protected] - name: Install Dependencies run: npm install - name: Environment Variables run: echo "${{ vars.ENV_FILE }}" > .env - name: Create Bundle run: npm run build env: NITRO_PRESET: cloudflare-pages - name: Create CF Pages Project uses: cloudflare/[email protected] with: apiToken: ${{ secrets.CF_API_TOKEN }} accountId: ${{ secrets.CF_ACCOUNT_ID }} command: pages project create ${{ github.event.repository.name }} --production-branch=deploy/production continue-on-error: true - name: Publish to CF Pages uses: cloudflare/[email protected] with: apiToken: ${{ secrets.CF_API_TOKEN }} accountId: ${{ secrets.CF_ACCOUNT_ID }} command: pages publish .output --project-name=${{ github.event.repository.name }} --branch=${BRANCH_NAME} @Anthodpnt .env isn't considered by Pages You'd need to add variables to the dashboard or use something like Terraform if you want to automate it w/o the dashboard or touching the API directly
Want results from more Discord servers?
Add your server