2

I want to do SPA application at the front-end will be the React, while the rest full api on laravel at the back-end. All I want to place on the same Apache server on the same domain ( myapp.com/index URLs my react application, requests will send to myapp.ru/api / ...).

Explain please, whether it is a normal practice, I understand I will have a problem with routing, and I always have to do rewrite to the index.html when page updating. Would not I have problems with the fact that I'm going to do ajax requests to the same domain as the front-end to the back-end.

Please explain that, and how that would all normally worked to configure. Or is it all a bad idea, and REACT to work on node.js server and separately laravel on apache. I would be very grateful for an explanation.

2
  • React doesn't care about your server. Just put it where you want and don't complicate things Commented Oct 21, 2016 at 6:11
  • Senks!!! But I have a problem with routing, when refresh page I have an error 404, I think, need to add rewrite rule, always redirect to index.html, yes? But I have a laravel routs from admin panel, Im not understan how to need configure my server. Or I need insert my component to markup which is located in my laravel views (index.php). Maybe you have link to example on git hub Commented Oct 21, 2016 at 7:36

1 Answer 1

0

SPA application does not require a server. You build your React app using webpack or browserify and server those static bundles to the client via Apache.

All the api calls will go to your backend laravel. (myapp.ru/api)

Sign up to request clarification or add additional context in comments.

3 Comments

Senks!!! But I have a problem with routing, when refresh page I have an error 404, I think, need to add rewrite rule, always redirect to index.html, yes? But I have a laravel routs from admin panel, Im not understan how to need configure my server. Or I need insert my component to markup which is located in my laravel views (index.php). Maybe you have link to example on git hub.
I could not fully understand your scenario, I guess you are using laravel router with react router To handle 404s caused by react-router use the following snippet in your app/Exceptions/Handler.php, method render() if ($e instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException) { abort(404); } return response(view('react.app.view'));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.