Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
Get for 99$

The Laravel project cannot access /api after deployment


After deploying the Laravel project on CentOS, try to access the http://127.0.0.1:8000/api link and find that the 404 page is automatically redirected, but http://127.0.0.1:8000 the link access is normal, you can also log in to the default account normally.


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (6)


It should be the latest version, downloaded and deployed in the last week.

PHP:8.1.13(If PHP-8.0.26 is used, an error is reported with an old version)
Node:v18.12.1(If you use v-14.16.1, you will get an error that the version is low)
npm:9.2.0
pm2:5.2.2
yarn:1.22.19



Hi,

Have you set the routes for API? Please check this file. /routes/api.php

Thanks



I've determined that this file exists, it can be edited normally, it just can't be opened in the link



Hi,

In the /routes/api.php file, please try to add this route.


Route::get("/user", function (Request $request) {
return $request->user();
});


Then in the browser, go to page /api/user. I did try this, the page should display. Please check if your API route has auth required.

Thanks



It can be accessed normally, thank you. Another thing is whether you can share the /api/login sample code



Hi,

Sorry, we do not have an example for the login API. You can consider checking this guide for the authentication login using the API.

https://laravel.com/docs/9.x/sanctum

Thanks


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(