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

Dvajs Frontend and Backend in different or same project, and how to do api calls #161

Open
AlexTemina opened this issue Aug 7, 2018 · 2 comments

Comments

@AlexTemina
Copy link

I put this question on stackoverflow, but there is no-movement at all there... so putting it here also.

I have a project made with dvajs using dva-cli. All my frontend is there, together with roadhogjs just like dva-cli installs.

Then I have a backend project made with a typical express and nodejs configuration. This backend has no webpages, only api calls using the port 3000.

The frontend has a proxy in the webpack config to bypass roadhog mock to localhost:3000 to make the calls to the backend instead of using the mock:

proxy: {
    "/api": {
      //"target": "http://46540a8f.ngrok.io",
      "target": "http://localhost:3000",
      "changeOrigin": true,
      "pathRewrite": { "^/" : "" }
    },
    hash: true,
  },

So when I make a call like:

return request('/api/users/login', {
    method: 'POST',
    body: params,
});

The application will call localhost:3000/api/users/login

This configuration is kinda smelly for production, I feel it cand be done more correctly, and I've been trying to find what is the proper configuration to put both projects together.

I was wondering what is the correct configuration for this, if I can put everything in one project (how) or should I use two like now.

In the case of using two, ¿What is the best way of making the api calls? And how do I deploy it? my hosting provider is telling me to upload the backend as the root project and then put the entire frontend in the public folder of the backend project, but I don't like that so much either.

@prionkor
Copy link

Was you able to resolve this? I am looking for the similar solution where I can set different url for the api server (production and dev)

@fhaze
Copy link

fhaze commented Oct 3, 2018

I usually use a reverse proxy like nginx in production to redirect HTTP/HTTPS properly to my backend and client. If your "Hosting Provider" doesn't support some kind of reverse proxing for your apps, I don't think there is much you can do but setup them separated.

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

3 participants