Redirecting to API/Docs/index.html folder in Lumen - laravel

So i have an API created with Lumen with some documentation done with Apidoc outside of the public folder and i'd like to serve it when the user goes to the URL http://apidomain.com/docs
This is the structure of the app
ProjectRoot
->API
->Auth
->Docs
->v1
->app
->bootstrap
->database
->public
...
Is there any way to create a route that sends the user to API/Docs?

It's done, it was actually my bad, when trying to call the file via routes it actually messed up the filepath for the other files. So when i looked in the dev tools on chrome i noticed i was getting 404's on my js and css files, hence the failure to load the ApiDoc

Related

Netlify Redirect not working in my app with React Hooks

Hi i try connect my page in netlify with a service external but i dont now how configurate _redirects I put this:
/api/* http://www.webservice.com/:splat 200
And my app get webservice and put these url https://myapp.netlify.app/api/products
i want that put http://www.webservice.com/api/products
my _redirects is in public folder , my app is developer in react-hooks with webpack
plese someone cant help me,
Put the following in your netlify.toml file:
[[redirects]]
from = "/api/*"
to = "http://www.webservice.com/api/:splat"
status = 200
Then browse to https://myapp.netlify.app/api/products and it'll show you the page at http://www.webservice.com/api/products.

Modify the URL generated with Route::apiResource without changing the name

I'm building a website where users can post ads : a VueJS app that requests routes on an Laravel API.
I have an AdController, with an Ad model, and my routing is done via stuff like :
Route::apiResource('ads', AdController::class)->only(['update', 'destroy']);
Route::apiResource('ads.photos', AdPhotoController::class)->only(['index']);
which generates routes like PUT "/ads/{ad}" or GET "/ads/{id}/photos"....
This works very well, and my VueJS app uses Ziggy to call the API by their route name
axios.get(route('ads.photos.index', id))
And... It still works flawlessly ! No problem at all, and I have a LOT of routes with a LOT of API calls.
Now my problem : we realised that URLs containing "ads" are blocked by adblockers. That completely shuts down all access to our website, and asking users to turn off the adblocker is NOT a solution.
I could change my routes to do something like
Route::apiResource('posts.photos', AdPhotoController::class)->only(['index']);
but I have a LOT of routes and I really don't want to rename everything, everywhere.
Is there an option to change apiResources generated URL, so 'ads.photos.index' would generate "/posts/{id}/photos" instead of "/ads/{id}/photos" ?

How to retrieve files from S3 in Laravel Vapor

I'm having a problem loading images in my html dynamically after storing them successfully with Laravel Vapor.
I have followed this documentation provided by laravel vapor to store files, and it works like a charm. I copy my uploaded files from the tmp directory into the root of my S3 bucket and then store the path of that file in my databases images table so that later I can return the file path to my front end and display the image in my browser.
Unfortunately this is always returning a 403 status code from AWS S3.
I could fix this by making my generated S3 bucket public, but that would raise a security issue. I believe this should work out of the box, not sure where I could have gone wrong... any ideas?
I am returning the uploaded image url using the Storage facade.
use Illuminate\Support\Facades\Storage;
return Storage::url($image->path);
Where $image->path is the file path in my S3 bucket.
I'm sure that the storage facade is working correctly because it is returning the correct url with the file's path.
I got the solution to this problem. I contacted laravel vapor support and I was told to set the visibility property for my file to public when I copy it to the permanent location, as stated in Laravel's official documentation here.
So after you upload your file using the js vapor.store method you should copy it to a permanent directory, then set it's visibility to public.
Storage::copy($request->path, str_replace('tmp/', '', $request->path));
Storage::setVisibility(str_replace('tmp/', '', $request->path), 'public');
I also noticed that your can set the visibility of the file directly in the vapor.store method by passing a visibility attribute with the respective value.
vapor.store(file, { visibility: 'public-read' });
As a side note: just 'public' will return a 400 bad request, it must be set to 'public-read'.

How to call sitemap.xml in codeigniter application

i have added sitemap.xml file to my codeigniter project.
And i call it on my localhost like that : http://localhost/demo/sitemap.xml
it runs without any issue.
But when i run it on live server http://example.com/demo/sitemap.xml
it says 404 page not found.
What is issue ?
you need to add below things in your config/routes.php file
$route['sitemap\.xml'] = 'demo/sitemap'; // your navigation path i.e. your controller_name/function_name

Polymer routing in Laravel

I have create a Polymer based Dashboard which I want to integrate with my Laravel site. My Dashboard is working fine but I have issues with routing in Polymer.
I want my Dashboard to reside at:
http://example.com/dashboard
I have set up my Laravel route as follows:
Route::get('dashboard',function(){
return View::make('polymer.dashboard');
});
and my dashboard urls should be like:
http://example.com/dashboard/#!/feedbacks
But, I am confused about what setting to make in app.js. Current app.js:
// Sets app default base URL
app.baseUrl = '/';
if (window.location.port === '') { // if production
// Uncomment app.baseURL below and
// set app.baseURL to '/your-pathname/' if running from folder in production
//app.baseUrl = '/dashboard/';
}
Under these settings, when I navigate to http://example.com/dashboard, when Polymer finishes loading, the url changes to http://example.com/.
If you haven't told the router to not use hashbangs then navigating to /dashboard won't work, it's expecting #!. You'll need to go into app/elements/routing.html and remove the line that says hashbangs: true. You'll also need to set the baseUrl to /dashboard/. Your server will also need to always return the index.html for any URL that starts with dashboard. So if the user tries to go to example.com/dashboard/feedback it should send down the index.html page again.
After you've made the change to routing.html, go into the devtools settings and enable Disable cache (with dev tools open). Then reload the app to make sure it isn't serving a cached version of the file.

Resources