Hosting a Vue js frontend and laravel backend(api routes) to a shared server?

Thi*_*ghe 5 php shared-hosting laravel vue.js

I built a single page web app with vue js as the front-end library and laravel as the back-end framework. Its now time to host it on a shared hosting service and have not found any clear steps on how to do this successfully with the Api Routes of the loading as programmed.

I copied content of laravel public folder and build files of vue js to the public_html folder in shared hosting. Then it's loading the frontend without data from the backend. Should I have to use two separate ip addresses for backend and frontend or is it possible to use same shared hosting storage for deploy my Vue js frontend and laravel backend(api routes).

//index.php of laravel
<?php
require __DIR__.'/../jewelpack_app/vendor/autoload.php';
$app = require_once __DIR__.'/../jewelpack_app/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
?>
Run Code Online (Sandbox Code Playgroud)
//web.php of laravel routes
<?php
Route::get('/{any}', function(){
   return view('index');//pointing to the index file of the frontend
})->where('any', '.*');
?>
Run Code Online (Sandbox Code Playgroud)

小智 0

首先,你应该将 laravel 项目分成 2 个文件夹

\n\n
    \n
  1. 将public重命名为public_html,复制并覆盖到共享主机的public_html文件夹
  2. \n
  3. 创建一个名为 'laravel' 的新文件夹,将其余项目数据复制到其中,并使用 FTP 移至托管,其中与您的 public_html 路径相同。例如:/var/www/laravel/ 、 /var/www/public_html/
  4. \n
  5. 编辑public_html中的index.php
  6. \n
\n\n

$app = require_once DIR.\xe2\x80\x99/../bootstrap/app.php\xe2\x80\x99;\n$app = require_once DIR.\xe2\x80\x99/../laravel/bootstrap/app.php\xe2\x80\x99;\n

\n\n

对于 Laravel 5 添加以下内容:

\n\n

$app->bind('path.public', function() {\nreturn __DIR__;\n});

\n\n

希望这能解决您的问题。

\n