'POST route doesn't work after Laravel Vue deploy on Ubuntu server
After deploying my Laravel app on Ubuntu server the broken POST no longer works, despite the migrations being successful Here are the reference files
web.php
// Submit route
Route::post('/submit', [HomeController::class, 'submit'])->name('submit');
VueComponent
submit() {
if (this.loaded) {
this.loaded = false;
this.success = false;
this.errors = {};
axios.post('/submit', this.fields).then(response => {
this.fields = {}; //Clear input fields.
this.loaded = true;
this.success = true;
this.goToHome();
}).catch(error => {
this.loaded = true;
if (error.response.status === 422) {
this.errors = error.response.data.errors || {};
}
});
}
}
,
/etc/apache2/sites-available/laravel.conf
<VirtualHost *:80>
ServerName http://162.19.27.126
ServerAdmin [email protected]
DocumentRoot /var/www/html/WinCond/public
<Directory /var/www/html/WinCond>
AllowOverride All
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
.htaccess
Options -MultiViews -IndexesRewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /index.php [L]
error request
Richiedi URL: http://162.19.27.126/submit Metodo di richiesta: POST Codice di stato: 500 Internal Server Error Indirizzo remoto: 162.19.27.126:80 Norme sui referrer: strict-origin-when-cross-origin
The route appears in php artisan route: list
Apache access.log
151.57.85.190 - - [30/Apr/2022:20:13:41 +0000] "POST /submit HTTP/1.1" 500 1144 "http://162.19.27.126/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36"
Solution 1:[1]
make sure you HTTP server allowed POST method, do you have check it?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Fajrul A |
