Run Vue.js and Laravel on the same server (same port)

半世苍凉 提交于 2021-02-19 05:38:13

问题


I am developing a website using Laravel as backend and Vue.js 2 as frontend. Now everytime i want to run my website I have to use 2 command:

php artisan serve

This will run the laravel server on port 8000

npm run dev

This will run the vue.js server on port 8080

Can I just run them on the same server (same port), with just one command only??


回答1:


If you use the Laravel app with Vue.js included in it, you don't need to run npm run dev.

In your case, you seem to have a decoupled frontend and backend. In that case, you don't really have the choice to host 2 different ports or hostname.

You can use the same port if you use a different domain. For example, you can use mydomain.com for the frontend and use api.mydomain.com for the backend/api.

Assuming you have a webpack frontend project, you can do npm run build, which will compile all your files to static html files in the dist folder. You then only need to point your host configuration file to this folder.



来源:https://stackoverflow.com/questions/50971052/run-vue-js-and-laravel-on-the-same-server-same-port

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!