4

I am creating a PWA using quasar, which uses vue.js at core.
Now the router is working fine. In production code, The address url is updating dynamically upon clicking route-links. Say, there are 4 routes, namely /user , /friends, /human, /robots. But when I visit one of those route paths using web address or say I reload the application/web page, when the route path is /robot or any other path, server reply with cannot GET /[route path]. I know that I had not set up the route handler at server, but I am not expecting this behavior. I dont want to make request to server like this.
While in dev mode, everything is working fine and as expected. when I visit /robot or any other route path , instead of contacting the server, it render the component that was bound to handle that route path

Comments
  • 0
  • 1
    You have a different devserver then you have in production, don't you?

    For all the paths the server should respond with the same files as in /
    If you don't want to make a request to the server each time the user clicks a link, you should use history.pushState
  • 0
    Yes ... In production I have my own server. Backend running on nodejs
  • 0
    @plusgut it is not making request while clicking links or change of state. Only url is changed....Say origin/ to origin/user. But it makes request when I visit origin/user directly either directly or by reload when state is origin/user. This makes me sick. Server respond as usual ... Cannot get /user
  • 0
    Yes obviously, how would the browser know it should use the html from / but not from /user?
    Your server has to respond for every route the same as /.
    And then your vue router can do his stuff.
  • 0
    But in case of development server, it simply routes the single page application, to the page as specified by the route path. I mean it handles request to /user on its own.

    So, did I fucked up something in production or "development server looks after this behaviour and routes according to for us and it's normal to see such differences in our production backend server"
  • 0
    Do I need to place a handler in my prod. Server and route each request to / and then also set up a way for front end to know which component to trigger to view?
  • 0
    So say ...When I visit /user .... Server will route this request to / and also tells front end application to route SPA to /user
  • 0
    Ok ... Will post it soon
  • 0
    @jalebiBhai no redirect should happen, just a simple 200 with the same content as the root route. Else you would loose your path and the vue router would show the /
  • 0
    @plusgut that means I have to set up more route paths ?
  • 0
    @plusgut because I wrote backend, when I was writing in vanilla. So the state of url was not changing. The view changes, the state of application changes with request but not the url
  • 1
    @jalebiBhai at the server you just define a catchall and deliver the index.html
  • 0
    @jalebiBhai okay you lost me, I would need some code.
  • 0
  • 0
    You want me to set up route handler to every route on vue router ?
  • 0
    I will show you code ASAP
  • 0
    One more thing. I have to make CORS from my dev server to production server to fetch data. I had configured the prod. server to accept CORS but it's not sending empty response. No json Data
  • 0
    Does thr OPTIONS request and response work accordingly?
  • 0
  • 0
    @jalebiBhai the browser useses the http method OPTIONS to get the cors informations from the server, to determine if it is allowed to make the actual request.
  • 0
    If you are talking about headers, then yes
  • 0
    @jalebiBhai I'm talking about the headers at the options response https://developer.mozilla.org/en-US...
  • 0
    I am just making GET request. So it doesnot require options header.
  • 0
    for a get request you don't need cors afaik but I'm not sure on this one.
  • 0
    But you need to specify at server what origins are allowed
  • 0
    Only for methods other than get and post, browser sends preflight request before sending actual request
  • 0
    @jalebiBhai ah, good to know.
  • 0
    @plusgut where I am wrong ?
  • 0
    @jalebiBhai what was the question?
  • 0
    That I am getting empty response while making CORS
  • 0
    @jalebiBhai you are talking about responses, aren't you?

    What does the console say?
  • 0
    200 status ok with empty body, which should be JSON
  • 0
    @jalebiBhai does the browser console say anything? What happens wjhen you do a request via curl?
Add Comment