How do I add a 404 page to a brunch.io project? - brunch

I have a default brunch project, how do I add a 404 page to it?
I tried putting a 404.jade file in the same folder as index.jade but didn't work.

It depends on your framework. There are programmatic solutions for Backbone, React, Ember, Angular. If you're just using brunch as a static site generator, there is no simple way to add 404 page. You'll need to adjust your web server like nginx or apache and add 404 page there -- see this question Nginx - Customizing 404 page

Related

how i can fix url redirection in netlify hosted site?

i have hosted a react site on netlify but redirect is not working as i want.
You see that here: https://unsplash-app.netlify.com/photo/C6-GjBAOtZc
for example if i go to /photo/h478dhek first time it load when i redirect from netlify site itself but, when i refresh page it just not work and say page not found. what should i do to make redirection work i want it to be.
i have tried creating _redirects file in my build directory but in official documentation it's not clear that redirection will work in refresh the page
Since this is a single page (React) app, have you tried a rewrite rule:
_redirects
/* /index.html 200
As you mentioned, this file would need to be in your build (deploy) directory after the build.

Serving StyleSheet and JS with Sails

I am a newbie at working with nodeJS and especially with the framework Sails.
I did my research and found that with sails you just need to put CSS-files under the the folder "assets" and call them directly with the URL, e.g. if I put the file custom.css in the folder "assets/foo" I should be able to access it via the URL "localhost:1337/foo/custom.css".
The problem is that my local server throws a 404 Error not being able to find the files, but strangely when I deployed the app to Heroku it works perfectly and I am able to access the css files.
Why is this not working locally?
Welcome to Sails! CSS is served automatically if you put it in your assets/styles folder. Your JS should be in assets/js folder as well. This way you can access it like localhost:1337/assets/js/myjs.js.
In your view - if you don't want to serve it everywhere with a layout - just put your tag like this: <link rel="stylesheet" href="/styles/myawesomestyle.css"> or <script src="/js/mypowerfuljs.js"></script>.
Remember, everything in assets will be made publicly available.
I really recommend that you read the docs HERE.

Can I run a CodeIgniter project inside a Laravel one?

I have a website that is currently using Laravel but i need to put inside a previous project made on codeigniter inside the website.
So my question is ...
How can i make the two frameworks work nicely with each other.
On my previous site I would use the route www.exampledomain.com/codeigniterproject and I would be redirected to a view that was inside the codeigniter project and handled by the controller.
But currently when I try to do this I get a 500 error.
I have an href trying to point to codeigniterfolder and I get the generic Laravel error "Sorry, the page you are looking for could not be found."
When i click on the link.
codeigniterfolder
My ftp looks like this ...
public_html where i have all the laravel public directory
laravelproject where everything that my laravel project requires
and then inside that folder i have the codeigniter one so the folders look like this laravelproject/codeigniterproject
Everything is set on the laravel side i have no problems with my routes or whatsoever inside laravel.
But I dont want to migrate all the codeigniter code to laravel it's just not an option, so I wanna integrate the codeigniter project inside my current laravel one.
You cannot have 2 index.php files in the same app, but you can change index.php to bootstrap Laravel or Codeigniter, according to some conditions you will set. It's not good, but it's doable.
But, really, there are many ways of doing this, the best one would be using your webserver (Nginx, Apache) and have it rewrite the url and send you to the Laravel directory or Codeigniter one accordingly.
What you cand do in Laravel is to configure a Redirect route to send to your old app, in a different VirtualHost (webserver, again):
Route::get('/oldapp', function() {
return Redirect::to('http://google.com');
});
If it is not really necessary to be in one directory, why don't you use subdomain?
You can put it simply like this:
on your laravel let's say www.yoursite.com
and on your codeigniter codeigniter.yoursite.com

Hosting a static site with Yesod

I'm experimenting with Yesod and I've created a simple scaffolding site with yesod. I've downloaded a bootstrap template site and wish to simply host this site with yesod. The template site has an index.html and a bunch of css and js files. This seemly simple task has baffled me. By my understanding, the site should be placed under the 'static' directory, I tried to use sendFile to send the index.html file in getHomeR, but only the content of the that file is displayed, without the css and js. Should I do this with a Subsite?
Thank you
Have a look in your browser console, most likely you're getting 404s due to bad relative links. I'd try using a redirect call to point to the static for so that all of the relative links are correct.

Routing problems with Codeigniter and Backbone.js

Here are the frameworks I am using:
Codeigniter
Codeigniter REST API
Require.js
Backbone.js
Running the app:
The htaccess file redirects everything through the Codeigniter index.php file.
There is a default route setup in Codeigniter to call the "Start" Controller.
The Start Controller calls the Start View (the only view in Codeigniter ).
The Start View holds the template for the entire website and makes a call to start Require.js
Require.js starts up Backbone and app works as expected.
Problem: Routing to other Backbone Views:
Now I want to route via Backbone to other Backbone "views".
The problem is when I try to provide a link like "localhost/otherPage" in an HREF the htaccess file fires, and Codeigniter tries to find that controller and I get a 404 generated by Codeigniter.
I have tried forcing a route in Backbone instead of HREF using `app.navigate("otherPage", {trigger: true});`, but I get the same 404 error generated by Codeigniter.
What direction should I take:
I would like to continue to use Codeigniter for its RESTFUL API, Models and some special validation features.
I also want to use Backbone and Require on the front end.
Can I change the htacess redirect to an index.html file that fires up Require and Backbone. Will the Codeigniter RESTFUL API Controllers still fire properly if I use this approach?
Do I create a view in Codeigniter for each page and have each page start Require + Backbone a new for each view?
I will be looking into Node.js very soon. Should I just trash the Codeigniter aspect of the the framework and go whole hog on Node.js?
Any guidance is much appreciated.
If you're not already doing it, you may want to route via Backbone through the hashtag changes (it's his normal behavior, pushState: false), as modifying the hashtag would in no way result in a server call, thus ignoring Codeigniter's router.
In your example, you would want to navigate to localhost/#otherPage.
Then use Codeigniter's router for your ajax REST calls.
Another way to keep your browser from submitting the http request with the HREF link is to just override it with javascript and jquery. Could be useful if you don't want to always use hashtags as Loamhoof suggested.
Example:
$('#linkID').on('click', function(event) {
event.preventDefault();
backboneRouter.navigate($(event.currentTarget).attr('href'), { trigger:true });
});

Resources