core
core copied to clipboard
Unable to set SEO site url to cloudflare deployment-url
I use the following workflow to deploy my website:
name: Deploy to NuxtHub
on: push
jobs:
deploy:
name: "Deploy to NuxtHub"
runs-on: ubuntu-latest
environment:
name: ${{ github.ref_name == 'main' && 'production' || 'preview' }}
url: ${{ steps.deploy.outputs.deployment-url }}
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- name: Install bun
uses: oven-sh/setup-bun@v1
- name: Install dependencies
run: bun install
- name: Build application
run: bun run build
env:
NUXT_UI_PRO_LICENSE: ${{ secrets.NUXT_UI_PRO_LICENSE }}
NUXT_SITE_URL: ${{ steps.deploy.outputs.deployment-url }} # not working: deploy is not started yet
- name: Deploy to NuxtHub
uses: nuxt-hub/action@v1
id: deploy
with:
project-key: eutimo-1zgd
Is there a way to retrieve the deployment-url earlier, or to set it after the build phase? I cannot retrieve the commit hash, as it is generated by Cloudflare. Therefore, using the first part of github.sha is not an option. It's actually feasible what I'm attempting to do?
For now I'm using this, but is not working well for older commits deployment in preview branches:
NUXT_SITE_URL: ${{ github.ref_name == 'main' && 'https://example.pages.dev' || format('https://{0}.example.pages.dev', github.ref_name) }}
How do you use the site url in your code? if there is no pre-rendering, you can get the url using useRequestUrl()
<script setup>
const url = useRequestURL()
</script>
Thank you for the reply, @atinux. I use the site URL for the Nuxt SEO module, primarily for OG images that are pre-rendered by the module, so I can’t use useRequestURL. To be honest, my situation is not a big problem, but it would be nice to have the ability to inject some NuxtHub variables in the app, like the generated deployment ID, into the environment.