Laravel doesnt send token - angularjs

I uploaded my app in the server i changed the folder structures i made the changes in index.php.Everything is working fine i can get the views(im using angular for the frontend and satellizer for the tokens)but whenever i try to make a call to my api through my app it doesnt send the token(im using jwt tokens).The token get on local storage but its not being send with every request,if i put the token in my url everything is working fine so im guessing its a problem with satellizer.should i change something in satellizer.js?

nvm i found it i should had change the .htaccess
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

Related

Can't retrieve static json file from react router routes on apache server

I'm in a situation where I have to locally build a React project and then upload it to a particular path on an Apache server. It all worked alright, except it took a while to figure out how to get the Apache server to respect the react-router routes. We eventually created a .htaccess file to add to the path where my app is being uploaded and this seemed to resolve the issue:
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# Fallback all other routes to index.html
RewriteRule ^ /events/new-year/index.html [L]
But I've had a request to put config variables in a json file in the /static directory so that these can be easily changed later on by the non-JS devs. Loading the JSON data from the file works just fine when in the application root. In the response I get:
{
data: {
eventDates: "20 Nov - 28 Nov"
localUrl: "http://localhost:3000"
pageTitle: "Some title"
serverURl: ""
year: "2023"
}
}
but when trying to load the json from any of the react-router routes I get a really weird output:
{
data: "<!doctype html><html lang="en"><head><meta charset="UTF-8"/><title>Current Page Title</title><link href="//www.google-analytics.com" rel="dns-prefetch"><link href="https://www.somesite.com/content/favicon-150x150.png" rel="shortcut icon"><link href="https://www.somesite.com/content....."
}
I cut most of the output because it's outputting ALL of the html for the index.html stored in the static folder. Why can't I get the a good response on these child routes?
I'm loading the json like so:
const data = await axios("./resources/data/config.json");
I've tried without the . at the front and I've tried without ./. I have found that I get a response of undefined with anything other than the ./
Thank you for reading, any help would be hugely appreciated 🙏
So it turns out that there was an issue with the path. Since the relative path didn't work (and returned html for some reason) I had to use only a / (non-relative path?). While this was returning undefined before, after looking at the network tab I realised why:
My application was sitting at www.website.com/some-path/my-application, so I needed to fetch static resources from www.website.com/some-path/my-application/resources, but instead it was looking in www.website.com/resources. So all I had to do was add /some-path/my-application to the url that I was using previously.
I hope this can one day help a lost traveller!

ReactJS - Multi-page app not working after being built for production

I have a multi-page app that I am trying to host on GoDaddy. After running npm build, I upload the files to GoDaddy as per their instructions and I am able to view my homepage without any trouble. When I try to navigate to another page such as the about page, I get a 404 error.
I have been searching and the solutions I attempted did not work. I tried adding "homepage": "http://www.kashy.com.au/", to my package.json. I also tried playing with the routes. (Adding the URL for the site in the path).
I am new to React and so I don't quite understand how the routes work. Could someone point me in the right direction for solving this problem?
You need to redirect all urls to ur site on Godaddy to point to the homepage/index as the routing is handled by your client/react app.
Create an .htaccess file to redirect all requests to index.html.
Sample
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
Steps
From your cpanel file manager, go to the root folder of your website (ie. public_html).
Create the (dot)htaccess file, by clicking on the top left menu
Right click on the file and edit and then paste the above
Save

Dynamic routes not working in React with Caddy

I have a React Application. I am using some routes that receives parameters in the URL (by GET), for example myapp.com/products/1 that works pretty good in local enviroment but no in my CentOS server. I have to mention that I am using npm run build to generate the static files.
For other side, I have running Caddy as HTTP server in the CentOS server, there I have problem only with the routes that includes parameters, so now am wondering if caddy have something to be with this issue.
Here the React people say:
If you’re using Apache, you need to create a .htaccess file in the
public folder that looks like this:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
So, how can I do that in Caddy. I have currently these lines for the site:
mysite.com {
root PathToProject/build/
log logs/pagelog.log
}
What is missing in order to can use parameters in the URL?
I have this config in my Caddyfile
rewrite {
if {path} not_match ^\/0.0.0.0
to {path} {path}/ /?_url={uri}
}
See if that helps, it took care of my routing issue (similar to what u have mentioned) for React App.

Merging frontend and backend for production

I have a web project, powered by Symfony2 for the RESTful API, and by AngularJS for the front. It seemed logical to divide the project in two subprojects : one for the backend, and the other one for the frontend. The frontend build system is made with Gulp.
What I am trying to do is configuring my web server, Apache2, so it would first try to match the request URL to the front-end files, and, if it didn't matched with any of those files, then pass to Symfony's front controller. How should I configure Apache2 in order to make this working ?
For the moment, I have put my two subprojects one next to the other in the file hierarchy, and configured Gulp to output compiled files to the web/ folder of my Symfony project, but I don't find that solution very efficient.
Use .htaccess.
If you are using $routeParams then set 404 url for everything that don't match.
Then write rule for this page with redirection:
RewriteCond %{REQUEST_URI} !^/?404$
RewriteRule .* index [R=301,L]
This is a sketch, but if You are using html5mode on false, then it may work.

Laravel not detecting auth token sent in the header and JWT package

I have set up a Ionic app and also started using Laravel for the API. Everything works great in postman and Ionic up until the point where I sent the token.
Using a package called Satellizer for angular, it adds the token in local storage to the header.
My issue is, I receive a token not provided error.
In postman, if call: /api/v1/authenticate/user?token=tokenkey
Then it works fine, if I also hard code that same url with the token set in the url params in angular as a http request then it also works.
However, when using postman and setting the authorisation params in the header to:
token : tokenkey
I get the missing token error again. In angular, when making the request to /api/v1/authenticate/user I have checked the header params and can see that a Authorisation has been set as " Bearer tokenkey".
Any help why its not getting picked up by Laravel? I have found information about Apache removing the auth header and added this:
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
To my Apache config file on MAMP, restarted but same issue.
Any more suggestions?
Try using
Authorization : Bearer { String_token }
Try using
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
in your public/.htaccess.
Related issue on StackOverflow: Laravel in Apache getting header value
Related issues on Github: https://github.com/dingo/api/issues/54 and https://github.com/sahat/satellizer/issues/300

Resources