angular express cycle without end

I'm experiencing an issue with my express/angular app where the index page is causing an infinite loop. Here's how I have set up my app:

app.configure(function() { 

    // setting up our express application
    app.use(express.logger('dev')); // logging every request to the console
    app.use(express.cookieParser()); // reading cookies (needed for auth)
    app.use(express.bodyParser()); // getting information from html forms

    app.set('views', __dirname + '/views');
    app.set('view engine', 'ejs');
    app.use(express.favicon(__dirname + '/public/img/favicon.ico')); 
    app.use(express.static(path.join(__dirname, 'public')));

    app.use(express.methodOverride());    
});

Here is my Angular app route provider:

var app = angular.module('myApp', ['ngRoute', 'angularFileUpload', 'rcWizard', 'rcForm', 'rcDisabledBootstrap', 'ui.bootstrap']).
    config(['$routeProvider', '$locationProvider',
        function($routeProvider, $locationProvider) {

            $locationProvider.html5Mode(true);

            $routeProvider
                .when("/login", { templateUrl: "/partials/login.ejs", controller: "LoginCtrl" })

                .otherwise({ redirectTo: "/login" });
        }
    ]);

My index.ejs file includes all the necessary scripts and styles:

<!doctype html>
<html lang="en" ng-app="myApp">
<head>
  <meta charset="utf-8">
  <title>Test</title>
  <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css"> 
  <link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css">   
  <link rel="stylesheet" href="css/style.css"/>
  <link rel="stylesheet" href="css/form-styles/rcWizard.css"/>
  <link rel="stylesheet" href="css/bootstrap-formhelpers.min.css"/>

</head>
<body>

  <div ng-view></div>

  <script src="bower_components/ng-file-upload/angular-file-upload-shim.min.js"></script> 
  <script src="bower_components/jquery/dist/jquery.min.js"></script>
  <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
  <script src="bower_components/angular/angular.js"></script>
  <script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js"></script>
  <script src="bower_components/ng-file-upload/angular-file-upload.min.js"></script> 
  <script src="bower_components/angular-route/angular-route.js"></script>
  <script src="bower_components/angular-resource/angular-resource.js"></script>

  <script src="javascripts/lib/helpers/sel_options.js"></script>
  <script src="javascripts/lib/helpers/xml2json.js"></script> 
  <script src="javascripts/lib/helpers/form-lib/jquery.bootstrap.wizard.js"></script>
  <script src="javascripts/lib/helpers/bootstrap-formhelpers.min.js"></script>
  <script src="javascripts/lib/helpers/form-src/directives/rcSubmit.js"></script>
  <script src="javascripts/lib/helpers/form-src/modules/rcForm.js"></script>
  <script src="javascripts/lib/helpers/form-src/modules/rcDisabled.js"></script>
  <script src="javascripts/lib/helpers/form-src/modules/rcWizard.js"></script>

  <script src="javascripts/app.js"></script>
  <script src="javascripts/services.js"></script>
  <script src="javascripts/filters.js"></script>
  <script src="javascripts/directives.js"></script>

  <script src="javascripts/controllers/LoginCtrl.js"></script>
</body>
</html>

And in express, I have the following routes configured:

app.get('/', function(req, res){
        res.render('index');    
    });

    app.get('/partials/login.ejs', function (req, res) {
        res.render('/partials/login.ejs', { 'message': 'test 111' });
    });

    app.get('*', function(req, res){
        res.render('index');
    });

Despite following common practices, my server keeps loading the script files repeatedly. Any ideas on what could be causing this issue?

EDIT Below is my login.ejs partial:

<% include navbar_public.ejs %>

<div class="container" ng-controller="LoginCtrl">
    <script>var message="<%-message%>";</script>
    <div class="col-sm-6 col-sm-offset-3">

        <h1 class="form-fonts"><span class="fa fa-sign-in"></span> Login</h1>

        <!-- show any messages that come back with authentication -->
    <div ng-if="message.length > 0" class="alert alert-danger">{{message}}</div>


        <!-- LOGIN FORM -->
        <form action="/login" method="post">
            <div class="form-group">
                <label>Email</label>
                <input type="text" class="form-control" name="email">
            </div>
            <div class="form-group">
                <label>Password</label>
                <input type="password" class="form-control" name="password">
            </div>

            <button type="submit" class="shimmy-button btn btn-success btn-lg">Login</button>
        </form>

        <hr>

        <p>Need an account? <a href="/signup">Signup</a></p>
        <p>Or go <a href="/">home</a>.</p>

    </div>

</div>

Answer №1

Discovering Four Key Aspects:

  1. It is important to review the contents of /partials/login.ejs, as there may be a potential issue within that file causing the error.

  2. The configuration in Angular's router instructing it to load /login when anything other than /login is requested could potentially lead to infinite loops. Testing different 'otherwise' scenarios might help identify and resolve the problem.

  3. Rendering the index page for any request except for specific URLs might result in unexpected behavior, especially considering the numerous script and JS tags present on the page. Furthermore, using relative paths for CSS/JS resources without a BASE HREF meta tag could exacerbate the situation by making incorrect requests.

  4. Utilizing tools like the browser's Network panel or Charles Proxy can assist in tracking the sequence of requests being made and identifying any underlying issues causing the complications.

I recommend providing details such as the template for the login.ejs partial and any unusual network requests you have observed if seeking further assistance. Describing where the app seems to be infinite-looping (server, client, both) will also aid in troubleshooting the problem effectively.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Trapped in a sticky situation with mongoose onsave

Within my MongoDB project, the user schema is structured as follows: var mongoose = require('mongoose'); var Schema = mongoose.Schema; const router = express.Router(); var userSchema = new Schema({ fName: String, mName: String ...

Tips for increasing the size of Material-ui Rating icons

I am currently utilizing npm to develop a widget. I aim to utilize the material-ui Rating component and have successfully integrated it. However, when I embed the widget on a webpage, the html font-size is set at 62.5%, causing the component to appear too ...

Angularjs and Angular (5) routing combo

I'm currently exploring the possibility of running angular alongside our existing angularjs application. Instead of immediately diving into the tedious process of transitioning to ngUpgrade, I wanted to attempt running them independently first. My ide ...

Exploring Methods for Retrieving offsetHeight and scrollHeight in AngularJS

I am currently developing a directive that requires three specific values: scrollTop offsetHeight scrollHeight projectModule.directive('scroller', function ($window) { return { restrict: 'A', link: function (scope, elem, attrs) { ...

Issue with jQuery - Exchanging positions of two elements fails after the initial swap

I'm currently using a function to perform a bubble sort on the content of multiple div elements. During each swap operation, it swaps the divs as well by utilizing the JQuery Swapsies plugin. The issue I’m facing is that after the initial swap, subs ...

Issues with jQuery Progress Bar Functionality

As a beginner in jQuery, I am currently working on creating an interactive progress bar using jQuery. My goal is to provide a set of checkboxes on a webpage so that when a visitor checks or unchecks a checkbox, the value displayed on the progress bar will ...

When I call getIdToken(), the token received is different than when displaying document data where it shows the accessToken

const user = { email: req.body.email, password: req.body.password, }; let errors = {}; if (isEmpty(user.email)) { errors.email = "Email field must not be empty"; } if (isEmpty(user.password)) { errors.password = "Password field mu ...

Adjust the color of the input range slider using javascript

Is there a way to modify the color of my slider using <input type="range" id="input"> I attempted changing it with color, background-color, and bg-color but none seem to work... UPDATE: I am looking to alter it with javascript. Maybe something al ...

Outputting HTML with functions

I have a function that returns HTML code. renderSuggestion(suggestion) { const query = this.query; if (suggestion.name === "hotels") { const image = suggestion.item; return this.$createElement('div', image.title); } ...

Is there a way to personalize the appearance of a specific page title in my navigation menu?

I'm currently working on customizing the menu of my WordPress theme to display a different color for the active page name. Although my CSS code works well for all page names except the current one: .navbar-nav li a { font-family: georgia; fo ...

I am interested in deleting an element from Firebase using JavaScript

I'm struggling to grasp the concept of deleting an item from my Firebase database. I have successfully created a function (saveEmployee) to add items, but removing them is where I hit a roadblock. HTML <tbody ng-repeat="employee in employees"> ...

Is the Scope Staying Static in AngularJS 1.4 when Input Text Changes and Two-Way Binding is Enabled?

Encountering a strange issue with AngularJS 1.4 (TypeScript). The problem lies within the controller where a variable is set and displayed in an input text box. Oddly, when attempting to edit the value in this text box and clicking on a button, the variabl ...

Is it possible to retrieve and display an object from an API using its unique ID?

I created a straightforward application. The main page displays a list of movies fetched using an API, and upon clicking on a particular movie, it leads to a new page with detailed information about that movie. On the details page, another API call is ma ...

Modify one specific variable within my comprehensive collection on Firebase Firestore

After clicking the button, I need to update a variable. The variable in question is "bagAmount" and it is stored in my firestore collection. Here is a link to view the Firestore Collection: Firestore Collection Currently, I am able to update one of the va ...

Please execute the npm install command to install the readline-sync package in order to fix the error in node:internal/modules/c

Having trouble installing npm readline as it keeps showing errors, even after trying different solutions. Tried deleting folders and uninstalling nodejs but the issue persists. Need help fixing this problem. ...

Using Swig template to evaluate a condition

I'm trying to achieve something similar using swig-template. var remId = $(this).attr('remId'); if (remId) { var end = remId.search('_'); var underscore = remId.slice(end, end + 1); var Id = remId.slice(end + 1, remId ...

Leveraging JavaScript along with the jQuery library and API to showcase information related to

Hey there! I have been working on this API that shows upcoming concerts, but I'm struggling to display the images associated with each concert. I've tried using for loops to iterate through the objects, and it seems like every sixth element has ...

Exploring the capabilities of useRef in executing a function on a dynamically created element within a React/Remix/Prisma environment

I've been trying to implement multiple useRef and useEffect instructions, but I'm facing difficulties in getting them to work together in this scenario. The code structure involves: Remix/React, fetching data from a database, displaying the data ...

Setting default values for JSON objects by analyzing the data of other objects within the array

I've been grappling with this issue for about 6 days now, so please bear with me if my explanation is a bit convoluted. I'm using NVD3 to showcase graphs based on data retrieved from BigQuery. While the data and graph setup are correct, the probl ...

An error is triggered when using db.listCollections() in an ExpressJS environment

I am currently working with ExpressJs and MongoDB, but I've encountered an issue with the following code: var db = monk(DB_URL); app.use(function (req, res, next) { req.db = db; next(); }); app.get("/view_collections", function (req, res) { ...