How to access express routes in front end?
-
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 inquasar.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 addseverMiddleware
then add location of the file, and everything just works. -
@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.
-
@beets Thank you for your response