Note that there are some explanatory texts on larger screens.

plurals
  1. POExpress routing freezes site when URL has a trailing slash
    primarykey
    data
    text
    <p>Whenever I load a page on my dev site with url of form <code>localhost:8000/news</code> everything loads correctly. However if I add a trailing slash, like so: <code>localhost:8000/news/</code> the site freezes. I can see that it is attempting to load a partial with path <code>/news/partials/footer</code> and some others. It is trying to load the partials that the home page uses but with a bad path. I don't know why this freezes Chrome, but it does.</p> <p>I've been trying for hours to figure out what's going on with this, but can't seem to get my head around why this happens. Here's the code I'm using (taking out some parts which, I promise, are irrelevant):</p> <p>app.js:</p> <pre><code>var app = module.exports = express(); // Configuration app.configure(function() { app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(express.static(__dirname + '/public')); app.use(app.router); }); app.configure('development', function(){ app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); }); app.configure('production', function(){ app.use(express.errorHandler()); }); var galleryProvider = new GalleryProvider(); galleryProvider.client.open(function(err, result) { galleryProvider.client.authenticate('user', 'pass', function(err, result) { if (!err) { console.log('Mongo connected. Listening on port ' + (process.env.PORT || 8000)); app.listen(process.env.PORT || 8000); } else { console.log(err); } }); }); // Routes app.get('/', routes.index); app.get('partials/:name', routes.partials); /* some backend routes that the page does not look at */ app.get('*', routes.index); </code></pre> <p>routes/index.js</p> <pre><code>/* * GET home page. */ //get correct directory path var filePath = __dirname.replace('routes', 'views/'); exports.index = function(req, res) { res.sendfile(filePath + 'index.html'); }; exports.partials = function (req, res) { var name = req.params.name; res.sendfile(filePath + 'partials/' + name + '.html'); }; </code></pre> <p>public/js/app.js</p> <pre><code>// Declare app level module which depends on filters, and services var lscGallery = angular.module('lscGallery', []); lscGallery .config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) { $routeProvider.when('/', {templateUrl: 'partials/home', controller: 'AppCtrl'}); $routeProvider.when('/artists', {templateUrl: 'partials/artists', controller: 'GalleryCtrl'}); $routeProvider.when('/exhibitions', {templateUrl: 'partials/exhibitions', controller: 'GalleryCtrl'}); $routeProvider.when('/news', {templateUrl: 'partials/news'}); $routeProvider.when('/about', {templateUrl: 'partials/about'}); $routeProvider.when('/contact', {templateUrl: 'partials/contact'}); $routeProvider.when('/admin', {templateUrl: 'partials/login'}); $routeProvider.otherwise({redirectTo: '/'}); $locationProvider.html5Mode(true); $locationProvider.hashPrefix('!'); }]); </code></pre> <p>Thank you!</p> <p>P.S. If it helps, I'm using <a href="https://github.com/dannyrdalton/angular-express-seed-with-html" rel="nofollow">this</a> as a seed for my site.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload