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

The $watch function does not trigger when there is no pattern match in the input change

I have implemented ngVal to enhance my input fields with AngularJS directives based on ASP.NET MVC Data Annotations. The model I am using contains the following annotations: [Display(Name="Test Number")] [Required] [RegularExpression(@"^[\d]{6}$", E ...

Troubleshooting JavaScript in Internet Explorer 9

Currently, I am encountering an issue while attempting to debug JavaScript .js files in my Solution using Visual Studio 2010 and IE 9. Despite placing breakpoints in the files, I am unable to debug successfully. I have attempted various troubleshooting ste ...

Designing personalized visualizations using elasticsearch

After setting up ELK tools, I have a desire to extract data from Elasticsearch and generate my own graphs without relying on Kibana. I've heard about tools like elasticsearch.js, but I'm unsure how to begin using it. What steps should I take in o ...

Creating a function for loading dynamic content in XSLT can be achieved by following these steps

When I call the function collapseandexpand() for static elements only, it does not work. Now, how can I create the same function to handle dynamic content in xslt? Javascript Code: <script language="javascript" type="text/javascript> <xsl:text&g ...

The anchor tag is not being used in the function call in an Angular application

Having trouble with calling the logout function inside the login controller. The setup involves a simple login and logout system using ui-router. After successfully logging in and navigating to another page, I encountered issues with calling the logout fu ...

Troubleshooting: AngularJS ng-repeat not rendering JSON data

I have successfully retrieved JSON data from a database using PDO in Angular. The data is being returned as expected when I encode it to JSON. However, I am facing an issue with displaying the data using ng-repeat in Angular. Although the div elements are ...

The functionality of changing the checkbox to "checked" by clicking on the span is not

How can I create a toggle button with a checkbox using css and jquery? Clicking on the span representing the toggle button should change the checked property of the checkbox. Currently, the span does not change the property, even though it triggers the c ...

java code unicode feature in csharp

Here's the code I am using: $(document).ready(function () { var breadCrumps = $('.breadcrumb'); breadCrumps.find('span').text("<%= ArticleSectionData.title %>"); }); The 'title' property contains values en ...

Configuring RingoJS to search for necessary modules within the node_modules folder

Currently, I am in the process of transitioning a service from nodejs to ringojs. My main hurdle involves the usage of require(). To illustrate, take a look at this snippet: var restify = require('restify'); The issue arises when RingoJS is una ...

Tips for preventing Uncaught SecurityError: Blocking a frame with origin in phonegap

I'm in the process of developing a phonegap application that serves as a miniature browser for a client's website. This app will allow the client's customers to access their favorite pages with ease. Once a user selects a favorite, it will b ...

Why aren't the validations being set when creating Angular forms using formControl.values?

I had to structure the form in a specific way in my app.ts file -> courseNameControl = new FormControl("", [Validators.required,Validators.minLength(2)]); contentControl = new FormControl("", Validators.required); form = { cours ...

Charts on the wrong position are displayed by AM

There seems to be an issue with the placement of some lines on the y-axis in my charts. Please refer to the code and snapshot below for more details. Here are the graphs: [{"bullet":"none","labelsEnabled":false,"dashLength":0,"lineThickness":3,"title":[[ ...

Vue: Develop a master component capable of displaying a sub-component

Is there a way to design a main component that is able to accept and display a subcomponent? Take the following scenario for instance: <Container> <Item/> <Item/> <SubMenu/> <Btn/> </Container> ...

In JavaScript, a true statement does not trigger a redirect

<label>Username:</label> <input name="username" id="username" type="text" value="testuser"> <label>Password:</label> <input name="password" id="password" type="password" value="test123"> <input value="Submit" name="su ...

What is the best way to style a value within a v-for loop inside an el-option element in Element UI?

I'm looking for a way to format the value in label(item.value) as a decimal within a v-for loop. Below is my code snippet: <el-form-item :label="label" :required="required" prop="Jan"> <el-select v-model=& ...

Adjust the content size to 100% based on the quantity of items in a row

I've been having a hard time creating an image gallery that adjusts its size automatically (width: 100%) based on the number of items it contains. For example, take a look at this gallery: http://codepen.io/anon/pen/eNMOEz .item { width: 75px; h ...

Parent passing down React state, but child component fails to update it

When a setState function is passed down from a parent component, I aim to update the state of the parent setter if the enter key is pressed. However, despite setting the state, nothing seems to happen and I am left with an empty array. Below is the snippe ...

sequenced pauses within a sequence of interconnected methods in a class

scenario: There are two javascript classes stored in separate files, each utilizing a different external service and being called within an express.js router. Refer to the "problematic code" section below: route routes.post('/aws', upload.sing ...

Guide on automatically extracting table rows and generating an Excel spreadsheet

I am currently working on a script that dynamically adds the first row (TH) to a table and then exports it to an Excel sheet. However, I am facing an issue where instead of appending each row, the script keeps stacking on top of the next table row. Below ...

The use of HTML in the static folder of NodeJS may lead to issues when loading assets using relative paths

For my NodeJS website, I have a static folder setup. What's interesting is that even though the files are stored in the folder, I still need to specify the path to it in the index.html file. When I include the folder name in the path, it works fine o ...