How to set up a website's URL properly - angularjs

I'm having trouble to decide how I should do to make my websites urls cleaner. The thing is, it's done with Angular AND Symfony2. Angular providing the front, and Symfony2 providing the api.
Here's my website's structure :
/api
/app => configurations go here
/bin => binaries
/src => your bundles/MVC code
/vendor => Symfony and 3rd party bundles
/web => this is where the web server document root should be pointed to
/front
/api -> Symlink to /api/web in the symfony part, working, but with app.php and app_dev.php
/css -> frontend CSS
/img -> frontend Images
/js -> frontend JS for AngularJS
/lib
/partials -> html templates used by AngularJS
index.html
Now the urls I get are www.project.dev/ which is home, rendered by AngularJS (/front), works perfectly, and www.project.dev/api/app(_dev).php/... rendered in Symfony2 but I want to remove the part :
app(_dev).php
I have two empty .htaccess, in / and in /api, do I need to use them ? Or do I have to use the Angular-route system ?
How am I suppose to do it ?

It's not clear how exactly you have your Symfony application setup, but I would recommend using the default Symfony directory structure, as it will simplify troubleshooting problems. The default directory structure is something like this:
/Symfony
/app => configurations go here
/bin => binaries
/src => your bundles/MVC code
/vendor => Symfony and 3rd party bundles
/web => this is where the web server document root should be pointed to
Since your document root is pointed to /web, you can have directories in there for your public assets, such as your /js, /img, and /css (Or you can look into Assetic, it allows lots of cool things like combining and compressing js or css.). The /web directory also has a .htaccess file included so that the app(_dev).php is removed from the URL.
Your /api can then be built using the standard Symfony routing, controllers, and views. You should read the Symfony routing documentation to get a grasp of how that works. A summary of how this works is:
create the route (ex. /api/users)
point the route to a Controller action (see the docs)
in the controller action, return the desired response
That's how I would recommend you structure your application. But if you would rather stick with the structure that you have, you will need to add a .htaccess file to the /api directory (which I assume points to the /web directory of the Symfony application), and take a look at this post for what the .htaccess file could contain.

Related

Deploying Angular Application to GitPages - Not Routing Properly

Disclaimer: I am not a frontend guy by trade. I am being asked to deploy an Angular application other engineers have created.
I have gone through the process of deploying an Angular application to GitPages and have also tried the handy Angular CLI GH Pages library. However, they both have the same issue, and I'm not sure if it's the application itself or how I am deploying it.
The base page loads fine, but all other resources (image/font files, links to other pages, etc.) do not load properly. This is because they are not using the proper base URL; our corporate GitHub makes us use https://....com/<org>/<repo> as the URL. All resources outside of the base page are not prepending the /<org>/<repo>/ part to the URL, so they are all returning 404s.
My index.html file in docs/ contains the proper base href="/<org>/<repo>/" and the docs/ folder contains all needed images and font files in its assets/ subdirectory, so I'm not sure what gives. I have also copied index.html to 404.html.
Am I missing something? Or is it possible that this web application was not created correctly for GH Pages?
Thanks in advance :-)
Change the base href to index.html only and all will work from there
base href="index.html"
From there it will take the path properly

How to deploy a react application on a static server

I have a react application build with create-react-app. Its using octoberCMS as the backend fetching data using Axios calls from the frontend. Till now I was developing keeping the build content of react inside a directory named 'react' in the root directory of octoberCMS installation. Hence the URL I was hitting was http://example.com/react/.
The problem is now I am done with the development phase and look forward to deployment. But I want my front-end to be served at http://example.com and backend to be served at http://example.com/backend (backend served as I want). How can I achieve this? I am fairly new to both frameworks.
I have tried keeping the build content along with the rest of the octoberCMS
First build your react app that will give you vendor.js[third party scripts] and your app.js[your actual app]
put them in to theme directory assets something
Then In Ocotber CMS make page with URL /:url? and paste your index.html content there.
it will be your root div and including js html, change path for js which points to the build js which you put in theme directory.
now what happens when anybody come to site
- we are serving same content as we do in dev build
- index.html with root tag and needed js
Now if use hit any other url like https://www.example.com/test/etc it also will be catch by /:url? (and all other requests) and home page served and our react app will work as we needed.
if any questions please comment.

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 - Move index.php to a different folder

I am trying to use AngularJS for the front-end and Laravel for the back-end. As such, I have setup the following folder structure:
/app
/app (contains Laravel)
/bootstrap
/vendor
/public
/api (want to place index.php for laravel here)
/app (AngularJS files)
app.js
bootstrap.js
index.html
And so I was hoping that by calling /api/myController/ I would get access to myController within the Laravel framework. However, when I call /api/ I get the following error:
The page isn't redirecting properly. Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
How can I accomplish this?
You could do that, and make changes in the index.php file and possibly in the start.php file on where to load the other files from, but you'd need to make sure any time you updated laravel you fixed up any references.
Why not just move the entire laravel application to inside the api folder?

CakePHP Subcake Redirect

I have a problem with CakePHP (1.3) project, i need to create projects inside the same domain/hosting of other project, like this:
app
cake
plugins
templates
vendors
ADMINONE (Cake project files here)
ADMINTWO (another Cake project files here)
.htaccess
index.php
README
The problem is, when I put the CakePHP code inside ADMINONE or ADMINTWO to create the other cake projects, if I put the url http://domain.com/ADMINONE/, the URL redirects to http://domain.com or the cake read the /ADMINONE as a controller name.
How can I redirect this URL to the directory ignoring the primary directory cake's redirect?
Dont forget to change your index.php inside the webroot folder. In there you can set up the
APP_DIR and the ROOT if need be.

Resources