This proxy will stand in front of your frontend server and the backend server and get the required data from the backend and pass it to your frontend while letting your browser think that you are all in the same domain.Grunt has a module grunt-connect-proxy that exists to help to solve this issue. To fix this issue, we can setup CORS through a proxy on Grunt. The requests from front-end server to the backend-server will result in same-origin policy errors due to the port difference. It happens because the backend Laravel service runs on port 8000 and the front end development server runs on port 8080. This is not possible with typical web server setup because XHR requests are not allowed to be cross-domain by browsers due to Cross-origin resource sharing (CORS) limitations.So, the problem here is as follows, you are developing the UI of your applications using some frontend JavaScript framework (say Angular) with Grunt as the build runner, and the backend of your application is being designed in some backend framework other than JavaScript/NodeJS (say Laravel), you might face problems accessing the backend while running Grunt server. For example, when you are developing your backend with anything other than JavaScript, you will face difficulty in accessing the backend data in your frontend without having to compile and deploy the code every time, you make any changes. Grunt can help you with automatically minifying your JavaScript or CSS files, reload your browser on every file change, can show you a comprehensive list of JavaScript errors, compile your SASS/LESS files into CSS files automatically and many other things.However, the most significant advantage of Grunt that I am going to discuss today is its ability to proxy your requests to the backend server. It is a JavaScript task/build runner that is written on top of NodeJS. For JavaScript projects, Grunt serves the similar purpose. Proxy Your Requests To The Backend Server With Gruntīy Yash Agarwal If you are working on large projects, it is undoubtedly a good idea to have a build script or some task scripts to help to automate some of the repetitive parts of the development process.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |