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

304 error while searching through songs. #19

Open
grali opened this issue Mar 7, 2018 · 0 comments
Open

304 error while searching through songs. #19

grali opened this issue Mar 7, 2018 · 0 comments

Comments

@grali
Copy link

grali commented Mar 7, 2018

Hello,
I was following the tutorial but when I search it does not filter down the queries and when I checked the network tab of chrome tools, I saw it is requesting the favicon multiple times. when I checked the server console I saw that the server has responded 304 error. I searched around this error a lot. everyone is saying it is because of cache and etag but disabling that didn't have any result.
These are my last attempts:

// SongsController:

module.exports = {
  async index (req, res) {
    try {
      let songs = null
      const search = req.query.search
      if (search) {
        songs = await Song.findAll({
          where: {
            [Op.or]: [
              'title', 'artist', 'genre', 'album'
            ].map(key => ({
              [key]: {
                [Op.like]: `%${search}%`
              }
            }))
          }
        })
      } else {
        songs = await Song.findAll({
          limit: 10
        })
      }
      res.header('Cache-Control', 'no-cache, no-store, must-revalidate')
      res.header('Pragma', 'no-cache')
      res.header('Expires', 0)
      res.header('Cache-Control', 'no-cache, no-store, must-revalidate')
      res.send(songs)
    } catch (err) {
      res.status(500).send({
        error: 'an error has occured trying to fetch the songs'
      })
    }
  },

// SongsSearchPanel

export default {
  data () {
    return {
      search: ''
    }
  },
  watch: {
    search: _.debounce(async function (value) {
      const route = {
        name: 'songs'
      }
      if (this.search !== '') {
        route.query = {
          search: this.search
        }
      }
      this.$router.push(route)
    }, 700),
    '$route.query.search': {
      immediate: true,
      handler (value) {
        this.search = value
      }
    }
  }
}

// SongsPanel

import SongsService from '@/services/SongsService'
export default {
  data () {
    return {
      songs: null
    }
  },
  methods: {
    navigateTo  (route) {
      this.$router.push(route)
    }
  },
  watch: {
    '$router.query.search': {
      immediate: true,
      async handler (value) {
        this.songs = (await SongsService.index(value)).data
      }
    }
  }
}

Thanks in advance.

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

No branches or pull requests

1 participant