问题
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