Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic Sitemap Generation from External Server not working in production on same machine #329

Open
Joshinn-io opened this issue Jul 31, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@Joshinn-io
Copy link

🐛 The bug

This is a bit of an odd one, I do have an open discord thread for faster conversing if it would help in the official nuxt discord: https://discord.com/channels/473401852243869706/1268206495007510590/1268206495007510590

In my nuxt.config.ts I have the following, where the URL endpoint returns an array of correctly formatted sitemap objects. I know this because when running the site locally with npm run dev it works great. I know this because in localhost I can see 3615 URL's pulled from the production API.

      sources : [
          'https://api.mcmodels.net/urls'
      ],
        cacheMaxAgeSeconds: 3600,
        xslColumns: [
            { label: 'URL', width: '50%' },
            { label: 'Last Modified', select: 'sitemap:lastmod', width: '25%' },
            { label: 'Priority', select: 'sitemap:priority', width: '12.5%' },
            { label: 'Change Frequency', select: 'sitemap:changefreq', width: '12.5%' },
        ],
    },

image
image

Note that since those screenshots I've removed the priority column from the sitemap page just to ensure the production server was building and receiving those changes properly, and it indeed is.

That same code is being ran full SSR on the production site at https://mcmodels.net/sitemap.xml yet it's not pulling any of the dynamic URLs.

And as you can see the sources URL is working well, especially known since it works great in localhost hitting the production backend server at https://api.mcmodels.net/urls

My only suspicion of this bug is that it doesn't like the "External" api being on the same IP?

🛠️ To reproduce

https://stackblitz.com/edit/nuxt-starter-thnwmt?file=nuxt.config.ts

🌈 Expected behavior

I can't reproduce in the stackblitz because simply exchanging the sources URL that I have working locally works just fine.

I expect production to match what local looks like, as I'm not sure why it doesn't. All I can think of is that the module doesn't like pulling "external" api data from the same machine since the backend is hosted on the same server?

ℹ️ Additional context

I have no idea what to produce to help out with what I've done wrong, the fact that it works locally with my backend and in stackblitz has me at a loss.

@Joshinn-io Joshinn-io added the bug Something isn't working label Jul 31, 2024
@Joshinn-io
Copy link
Author

Joshinn-io commented Aug 5, 2024

As a followup, I found a workaround that works but would still be nice to get this issue fixed. I made my nuxt.config.ts have

  sources: [
        '/api/__sitemap__/urls'
    ],
to basically point to internal file, and that file:
export default defineSitemapEventHandler(async () => {
    try {
        const response = await fetch('https://backend.api.url/urls');
        const data = await response.json();

        if (Array.isArray(data)) {
            return data;
        } else {
            console.error('Unexpected data format from backend.api.url/urls');
            return [];
        }
    } catch (error) {
        console.error('Error fetching sitemap data:', error);
        return [];
    }
})

calls the same endpoint. This seems to work just fine.

@cayque10
Copy link

cayque10 commented Oct 3, 2024

I have the same problem. In the development environment it works well, but in production it does not return dynamic urls.

File nuxt.config.ts:

export default defineNuxtConfig({
  modules: ['@nuxtjs/tailwindcss', '@pinia/nuxt', '@nuxt/image', 'nuxt-gtag', "@nuxtjs/sitemap"],
  
  sitemap: {
      exclude: ['/admin/**', '/user/**', '/auth/**'],
      sources: [`${apiUrl}product/seo/sitemap`]
    },
})

package.json:

  "private": true,
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare"
  },
  "devDependencies": {
    "@nuxt/image": "rc",
    "@nuxtjs/sitemap": "^6.0.1",
    "@nuxtjs/tailwindcss": "^6.8.0",
    "@types/crypto-js": "^4.1.1",
    "nuxt": "^3.13.1",
    "nuxt-gtag": "^0.5.7"
  },
  "dependencies": {
    "@pinia/nuxt": "^0.4.8",
    "@popperjs/core": "^2.11.7",
    "crypto-js": "^4.1.1",
    "h3-formidable": "^0.3.2",
    "maska": "^2.1.8",
    "pinia": "^2.0.34",
    "v-money3": "^3.24.0",
    "vee-validate": "^4.8.6",
    "vite-svg-loader": "^4.0.0",
    "vue": "^3.5.3",
    "vue-native-websocket-vue3": "^3.1.7",
    "yup": "^1.1.1",
    "yup-locale-pt": "^0.0.9"
  }
}

Localhost:

image

Production:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants