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

sitemap.xml not generating #18

Closed
crabdul opened this issue Mar 9, 2018 · 11 comments
Closed

sitemap.xml not generating #18

crabdul opened this issue Mar 9, 2018 · 11 comments

Comments

@crabdul
Copy link

crabdul commented Mar 9, 2018

The sitemap is not running when I run the build command.

Below is the configuration for modules and sitemap.
I am importing axios at the start of the nuxt.config.js file

  modules: ['@nuxtjs/sitemap'],
  sitemap: {
    hostname: 'https://karaimusic.com',
    routes () {
      return axios.get('https://karaimusic.co.uk/wp-json/wp/v2/posts?categories=2')
        .then(res => res.data.map(track => {
          const path = '/tracks/' + track.slug
          console.log(path)
          return path
        }))
    }
  }

Axios is getting the data properly because I'm able to print out the slugs of my posts properly

/tracks/parquet-courts-almost-had-to-start-a-fight-in-and-out-of-patience
/tracks/iceage-catch-it

Where am I going wrong?
What else can I check?

This question is available on Nuxt.js community (#c11)
@NicoPennec
Copy link
Member

@crabdul, I have tried your use case, it works fine for me!

My steps to reproduce:

// starting from an empty project with Nuxt.js 1.4.0 from starter-template

$ npm install @nuxtjs/sitemap
$ npm install axios

// edit the nuxt.config.json with your configuration,
// add on top `const axios = require('axios')`

$ npm run build
$ npm run start

// open http://localhost:3000/sitemap.xml

@crabdul
Copy link
Author

crabdul commented Mar 11, 2018

Thank you for your help!

I assumed it wasn't generating the sitemap because the sitemap.xml file doesn't appear in .nuxt when I run the build command

@crabdul crabdul closed this as completed Mar 11, 2018
@amjadkhan896
Copy link

amjadkhan896 commented Feb 12, 2019

is it possible to make one sitemap file and in that file, we include 5 sitemaps other files?
Like I want to divide the big sitemap file into smaller 2 or 3 files,
Because my links combination are crossing more than 50 or 60k

@amjadkhan896
Copy link

@crabdul did you fixed the issue, did you put the modification date and frequency while using the axios request. I am also stuck

@arnabrahman
Copy link

arnabrahman commented Jun 10, 2020

@crabdul how did you solve it? I am using docker.

@NicoPennec
Copy link
Member

@arnabrahman what is your issue?

@arnabrahman
Copy link

@NicoPennec this works fine for me when i run

npm run build
npm run start

from my project. But when i build my project in docker and navigate to "/sitemap.xml" route, it takes me to 404 route.

@NicoPennec
Copy link
Member

@arnabrahman can you share your nuxt.config.js and docker config to reproduce?

@arnabrahman
Copy link

@NicoPennec At first created a nuxt project using create-nuxt-app command. Then installed @nuxtjs/sitemap. Build the dockerfile,run it and navigate to sitemap.xml where 404 error happens. I don't know if i am missing something or not. Github link of this

nuxt.config.js

export default {
  mode: 'universal',
  /*
  ** Headers of the page
  */
  head: {
    title: process.env.npm_package_name || '',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: process.env.npm_package_description || '' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },
  /*
  ** Customize the progress-bar color
  */
  loading: { color: '#fff' },
  /*
  ** Global CSS
  */
  css: [
  ],
  /*
  ** Plugins to load before mounting the App
  */
  plugins: [

  ],
  sitemap: {
    cacheTime: 1000 * 60 * 60 * 2,
    gzip: true
  },
  /*
  ** Nuxt.js dev-modules
  */
  buildModules: [
  ],
  /*
  ** Nuxt.js modules
  */
  modules: [
    '@nuxtjs/sitemap'
  ],
  /*
  ** Build configuration
  */
  build: {
    /*
    ** You can extend webpack config here
    */
    extend (config, ctx) {
    }
  }
}
Dockerfile

FROM node:12.18.0-alpine AS BUILD_IMAGE

WORKDIR /usr/src/app

# update and install dependency
RUN apk update && apk upgrade && apk add --no-cache --virtual .gyp python make g++

COPY . /usr/src/app/

RUN npm install
RUN npm run build
RUN npm prune --production


FROM node:12.18.0-alpine

WORKDIR /usr/src/app

COPY --from=BUILD_IMAGE /usr/src/app/.nuxt ./.nuxt
COPY --from=BUILD_IMAGE /usr/src/app/node_modules ./node_modules
COPY --from=BUILD_IMAGE /usr/src/app/package.json ./package.json
COPY --from=BUILD_IMAGE /usr/src/app/static ./static

EXPOSE 5000

# set app serving to permissive / assigned
ENV NUXT_HOST=0.0.0.0
# set app port
ENV NUXT_PORT=5000

# start the app
CMD [ "npm","run", "start" ]
# docker build
$ docker build -t my-app .

# run docker project
$ docker run -p 5000:5000 my-app

@arnabrahman
Copy link

Ok problem identified. I have to also copy nuxt.config.js into my container. And it works fine.

COPY --from=BUILD_IMAGE /usr/src/app/nuxt.config.js ./nuxt.config.js

@crytos
Copy link

crytos commented Jul 13, 2020

I understand the hustle, but please try this link.

#106

That worked for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants