No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    How to access express routes in front end?

    Framework
    2
    3
    110
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      marvenwilsons last edited by

      New to Quasar here,

      I want to build a website, I want to be able to call the express routes in the vue component, I know how to install and set up axios in quasar, I just cant get my head wrap in how to set up such functionality.

      in my Vue file I want to be able to do the following:

      export default{
           mounted() {
               const get = this.$axios.get('/some/route')
          }
      }
      

      I cant figure out where should I put my nodejs file, my express routes,
      I dont know what to add in quasar.conf.js is there something I need to install?

      // my server file, where do I put this?
      const express = require('express')
      const app = express()
      
      app.get('/route', () => {
         /** do something */
      })
      ...
      
      module.exports = {
         path: '/some',
         handler: 'app'
      }
      

      I guess I am looking for similar functionality like in nuxt.js where I can just add severMiddleware then add location of the file, and everything just works.

      beets 1 Reply Last reply Reply Quote 0
      • beets
        beets @marvenwilsons last edited by

        @marvenwilsons I’m not familiar with nuxt if there’s any special functionality there, but with quasar / vue, you will want to put your axios in a separate nodejs project in a completely different project directory. Express runs on the server, and quasar / vue in the browser. What you should then have is an express server running at (for example) 127.0.0.1:3000 and the quasar dev server running at 127.0.0.1:8080. You’d then make your axios request to 127.0.0.1:3000. Once you get that going, you can use some of webpack’s api proxing, but best to get one step at a time.

        M 1 Reply Last reply Reply Quote 0
        • M
          marvenwilsons @beets last edited by

          @beets Thank you for your response

          1 Reply Last reply Reply Quote 0
          • First post
            Last post