I am using angular for frontend and laravel for backend.
When I start the client angular app using below command:
ng serve --open --proxy-config proxy.conf.json
It loads js files from laravel backend public folder.
Angular requests (in browser console)
GET http://localhost:4200/server/client/inline.655c959301e57e1e55b1.bundle.js return 404 not found or ::net::ERR_ABORTED
When I open it in browser without port, it loads.
I am using below proxy setting in angular:
{
"/secure": {
"target": "http://localhost:80/server",
"secure": false
},
"/storage": {
"target": "http://localhost:80/server",
"secure": false
}
}
Why its request to
server/client/...............
If you're using ng serve, it should be directed to
http://localhost:4200/inline.655c959301e57e1e55b1.bundle.js
Check your routes path.
The proxy setting doesn't change any setting to the internal routes. Unless you try to access Angular webpack in Laravel Public directory, but it doesn't make sense.
Maybe you can try to build angular without proxy and put in Laravel public dir. See if it's working.
Related
I'm trying to deploy a Slim v3 project on a dockerized nginx reverse proxy on my dedicated server (let's supose the URL is www.mywebsite.com) and I assigned a 'subdirectory' ussing the reverse proxy (for example /my_project).
The problem is that when I want to go to a route diferent to / in the 'subdirectory', the subdirectory part of the URL is deleted.
For example, when I go to www.mywebsite.com/my_project it works fine, but when I want to go to the route www.mywebsite.com/my_project/register the browser redirects me to www.mywebsite.com/register, deleting the 'subdirectory' part of the URL.
I've already tried to force a base url but without success changing the APP_URL variable on index.php
An example in Laravel of what I want to achieve with Slim
I've made deploys on Nginx Reverse Proxy using the Laravel Framework and I faced this issue, but I solved it defining the APP_URL in .env file like www.mywebsite.com/my_projectand forcing the root url using the next code
public function boot()
{
URL::forceRootUrl(Config::get('app.url'));
if (Str::contains(Config::get('app.url'), 'https://')) {
URL::forceScheme('https');
}
}
I hope that this example of Laravel helps me to clarify the problem i'm facing.
Sorry if the title doesn't make sense. I will elaborate more here.
Background. This works on my local using valet but not on Ubuntu 18.04 Production. I am using Larvavel 6.18.7 and nginx verison 1.17.3 and have redirects using Certbot for http to https.
I thought it was an all round issue with the platform but have got it down to an issue with just a route to Route::post('/business', 'BusinessController#store');
I have been debugging for hours so I have now created some test pages to hopefully explain this better.
I have now have two Axios POST calls in a Vue Component but its actually just the business one.
axios.post('/business', {'q':"hello"})
.then(res => {
console.log(res)
})
.catch(error => {
console.error(error)
});
axios.post('/test', {'q':"hello"})
.then(res => {
console.log(res)
})
.catch(error => {
console.error(error)
});
The issue I am experiencing is the /business route when this is called I get a 301 Redirect. Laravel doesn't like the trailing / so thats why it is 403 but it shouldn't be redirected.
Both these go to the same place, i have placed these at the top of my routes to check that the business isn't called anywhere else:
Route::post('/test', 'BusinessController#store');
Route::post('/business', 'BusinessController#store');
The calls are exactly the same, they go to the same location but the /business has a redirect.
I've tried clearing the route cache. There's no further information in my logs. I've seen
When using routes, you need to make sure the name does not overlap with the content/structure of your public folder. If there is an overlap, the .htaccess file will just try to access the file in stead. Because the file is a folder, it tries to load it as an ftp page(301), but can't because it is disabled for security reasons(403).
In my laravel project, I have a post route defined like this:
Route::post('myroute', function(){
// Do things here
}
and in my app.js, I am using a library called axios and I am also passing the myroute as the argument of it's axios.post() method:
axios.post('myroute', { value: myargument }).then(function(response) {
// Do thigs here
}
In my local machine, the axios call works fine. But in the remote machine, it doesn't. Because in the server, the application is not uploaded directly under the root. It's uploaded in: http://example.com/level1/level2 directory.
So when the ajax call is performed on the server, it returns a 503 service unavailable response because it looks for http://example.com/myroute. But the application is not there at all. How do I tell it to look for the myroute route from the directory I am currently in (level2) and not from root?
I tried changing the path in axios.post() like this: /../../myroute but the ajax call is still pointing from the root. But works only if I hardcode the path like this: /level1/level2/myroute. What can I do about it?
If I correctly understood then you need to use the java script to generate your URL sending.
Use the location.href to get your current URL
var url = location.href+'/myroute';
Might the relative path be the same in both environments? If you start the path with a /, it looks to the root. If you just do foldername/asset.ext it will be based on the working directory of the script.
You can use a configured instance of axios this way.
import axios from 'axios';
var instance = axios.create();
if (process.env.NODE_ENV == 'production') {
instance.defaults.baseURL = 'http://example.com/level1/level2'
}
export default instance
Now you use this instance instead of default axios.
It will use the subdirectory URL in production
I've changed my APP_URL=https://example.com, I've added this into my AppServiceProvider's boot method:
/** Enable HTTPS */
if(env('REDIRECT_HTTPS')) {
$url->forceSchema('https');
}
And I've run php artisan cache:clear, php artisan view:clear and php artisan config:clear. I still can't get assets and dynamic routes to use https. Just getting the error:
Mixed Content: The page at 'https://example.com/' was loaded over HTTPS, but requested an insecure stylesheet 'http://example.com/css/app.css'. This request has been blocked; the content must be served over HTTPS.
I know I can use secure_asset instead of asset and that should work, but I need this to be dynamic, as I still need to serve the http version of the site for now on another domain.
The asset() helper relies on a couple possibilities to determine whether to make a HTTP or HTTPS URL:
$_SERVER['HTTPS'] being on. This is Apache's way of doing things. For nginx, you can set that server param yourself in the config.
$_SERVER['HTTP_X_FORWARDED_PROTO'] being https.
If you're behind a load balancer, it's probably sending the X-Forwarded-Proto header, but Laravel doesn't trust it by default because it can be set by a malicious user in some cases. You can tell Laravel to trust this header coming from your load balancer using the TrustedProxy package. (edit: This is now built into Laravel)
See also: Symfony2: getScheme does not return 'https' (Laravel uses Symfony's getScheme() function for this)
in .env file please change the value local to production
APP_ENV=production
I have a problem with Laravel/Angular AJAX integration :
I can directly go into my laravel routing by putting it on my own but Angular AJAX doesn't work. This is what I get from my browser console :
GET path to my laravel route (Not Found) angular.js:8611