Lumen dot in URL - laravel

I am serving a file via Lumen route and URL contains dot and extension file. and when URL contains dot Lumen look for resources not executing routes.
I've tried to run it on production server and it works but on development environment it does not work.
This is my route:
$router->get('file/{file}', function (Request $request, $file) {
echo $file;
});
When I try to open this URL route will be run:
http://localhost:9001/file/photo.jpg
When I try to open this URL Lumen look for resources:
http://localhost:9001/file/photojpg

Related

Laravel vue 3 remove /build/ from url

Let me start of with the fact that im new to laravel and english is not my main language so dont mind my grammer. I have a project that has a laravel api with a vue front-end. The Laravel web routing redirects everything to a single blade file that contains the vue app. this way i can use the vue routing. This is has all been working fine for a while now but now im trying to build for production and ive run into the following issue.
after using npm run build to build for production laravel puts /build/ to every route im using through vue. This is very logical given that it uses the build folder in the public directory like it should. But its ofcourse verry ugly for the users. Is there a way to remove the /build/ from the url? (appart from redirecting /build/ to / in the .htacces file on the server)
You can set the environment variables in .env file for javascript using VITE_ prefix as below:
Please add the new environment variable in .env file as below:
VITE_BASE_URL="/"
Made the router related changes in your Vue file as below:
const router = createRouter({
history: createWebHistory(import.meta.env.VITE_BASE_URL || '/'),
routes: [
.....
],
})
Problem from import.meta.env.BASE_URL in vitejs, in build mode this import.meta.env.BASE_URL result "/build/" and development mode result, is "/"
I don't know where to change this, but I fix this problem with
const router = createRouter({
history: createWebHistory("/"),
routes: [
{
......
}
]
})
and fix it

Laravel 5 url() doesn't contain scheme

I'm quite new in Laravel.
I'm working on an existing Laravel 5.8 project. I installed it locally with HomeStead.
I noticed a strange behaviour on redirects: considering my homepage is http://project.test/, when there is a redirection, say to /redirected, Laravel sets the location to http://project.test/://project.test/redirected! As I tried to figure out wat was going on, I saw that the url('/') Laravel function gives me ://project.test instead of http://project.test.
request()->getSchemeAndHttpHost() gives http://project.test.
Example in web.php:
Route::get('/info', function (Request $request) {
echo url('/'); // gives '://project.test'
echo '<br>';
echo request()->getSchemeAndHttpHost(); // gives 'http://project.test'
// This will lead me to 'http://project.test/://project.test/redirect'
// return redirect('/redirect');
});
I have the same problem with the static resources.
Config:
'url' => env('APP_URL', 'http://project.test') in config/app.php
APP_URL=http://project.test in the .env file.
I certainly missed something, but so far I couldn't find any information about this.
when you redirect check if you wrote : "Redirect::home()" , try "return Redirect::home()" (note the return)
I tested your routes, and it's working nicelly for me.
I give you my config,just replace "tlara" wich is my project name with your's : "project"
in host.sam
127.0.0.1 tlara.test #laragon magic! (note is not my ip 192.xx.xx, 127.0.0.1 is universal localhost)
in .env
APP_URL=http://localhost
..
REDIS_HOST=127.0.0.1 (i don't know if it is revelant)
..
SESSION_DOMAIN='localhost'
clear
clear caches (routes, caches, view) (may be useless)
test
tlara.test/info
127.0.0.1/info
localhost/tlara/public/info

Mixed content issue- Content must be served as HTTPS || Lumen || Swagger API

Mixed Content: The page at 'https://api.xyz.com/api/documentation' was loaded over HTTPS,
but requested an insecure stylesheet 'http://api.xyz.com/swagger-ui-assets/swagger-ui.css?v=26ec363936a21921c9fec290e551e3eb'.
This request has been blocked; the content must be served over HTTPS.
I know how to solve this problem in Laravel but unable to solve this in case of Lumen.
Tried Solutions:
Added below line in AppServiceProvider
URL::forceSchema('https');
update boot() method in app/Providers/AppServiceProvider.php file as bellow
public function boot()
{
if(env('APP_ENV') !== 'local') {
URL::forceScheme('https');
}
}
alse update APP_ENV to APP_ENV=prod in .evn file
Check the APP_URL in the .env file which is set to http://localhost
Heroku uses https://appname.herokuapp.com since it's in production but lumen uses http://localhost for dev mode so I fixed it by running heroku config:set APP_URL=https://localhost

Laravel 5.5 | Redirect main domain to public folder

I have laravel 5.5 project uploaded to live hosting on /public_html/commerce.
When I go to domain.com/commerce/public then everything looks working perfectly.
But when I point the domain directly to commerce/public, so; when I visit domain.com then all links got broken like this:
domain.com/product/domain.comget-item-sizes-detail
Route for above link:
Route::post('/get-item-sizes-detail', 'ProductController#getItemSizesDetail');
Ajax request:
url:'get-item-sizes-detail',
type:"POST",
dataType:"JSON"
Any suggestions?
Here's a quick fix:
Create a folder in your public_html directory
I will call it webroot you can call it anything you want.
Put all the content of your Laravel public folder inside public_html directory
Put all other remaining files and folder of your Laravel project inside webroot
Edit public_html/index.php, change line 22 require __DIR__.'/../bootstrap/autoload.php'; to require __DIR__.'/webroot/bootstrap/autoload.php'; and change line 36 $app = require_once __DIR__.'/../bootstrap/app.php'; to $app = require_once __DIR__.'/webroot/bootstrap/app.php';
So you don't have to point your main domain to public_html/public again.
Just accessing the maindomain.com should have your project running just like using PHP artisan serve. But still using a service like Forge or Fortrabbit is the best way to host your Laravel app.
Good luck

Unable to get laravel/database and restler working with versioning

I have an existing website up and running, and now I want to add a REST interface to it in an api subdirectory. I'm not able to get this to work with versioning. I installed like so (no errors):
$ php ~/bin/composer.phar create-project laravel/database --prefer-dist api
$ cd api
$ php ~/bin/composer.phar require restler/framework 3.0.0-RC6
Then I uncommented the lines in public/index.php related to Restler and add a new API class that just echos a string. If I run this via php artisan serve and look at it through the localhost URL, then the method works.
Now I want to enable versioning, so I added these lines to public/index.php
use Luracast\Restler\Defaults;
Defaults::$useUrlBasedVersioning = true;
And in app/controllers I created a v1 directory and moved Test.php into that. I also added a namespace directive to the file of the format namespace A\B\v1
When I restart the artisan server and query the API, I get a 404 error. I've tried as both http://localhost:8000/Test and http://localhost:8000/v1/Test
What have I forgotten to do?
Here is how I made it to work. Note the folder where I placed the api class file.
in index.php
use Luracast\Restler\Restler;
use Luracast\Restler\Defaults;
Defaults::$useUrlBasedVersioning = true;
$r = new Restler();
$r->addAPIClass('A\B\Test');
Test.php kept in app/controllers/A/B/v1/Test.php
<?php namespace A\B\v1;
class Test
{
public function get()
{
return 'working';
}
}
Both http://localhost:8000/v1/test and http://localhost:8000/test return "working"

Resources