Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7953845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:15:08+00:00 2026-06-04T03:15:08+00:00

total node.js noobie, started playing with demo codes from various tutorials and websites and

  • 0

total node.js noobie, started playing with demo codes from various tutorials and websites and I noticed something that I do not understand…

namely, if I have index.html in my /public folder, then

app.get("/", function (req, res) {
    console.log("get /");
    res.redirect("/test.html");
});

is simply never called. As soon as I rename index.html to index2.html then the method is called and I am redirected to /public/test.html

this is what I have:

var io = require('socket.io'),
    express = require('express'),
    MemoryStore = express.session.MemoryStore,
    app = express.createServer(),
    sessionStore = new MemoryStore();

app.configure(function () {
    app.use(express.bodyParser());
    app.use(express.cookieParser());
    app.use(express.session({
        store: sessionStore,
        secret: 'secret',
        key: 'express.sid'
    }));
    app.use(express.static(__dirname + '/public'));
});

and the rest is pretty much taken from this tutorial: http://www.danielbaulig.de/socket-ioexpress/

The same issue appears with any other file. If i have /public/test.html, then when I call

http://localhost:8201/test.html

this app.get is not called:

app.get("/test.html", app.authenticateUser, function (req, res) {
    console.log("get /test.html");
    res.redirect("/test2.html");
});

When I remove the test.html then I get forwarded to test2.html…

The reason I am trying to redirect is if the user is not logged in I do not want him to open index.html but rather want to forward him to login.html, which is not possible if index.html exists. The only “solution” is to do it client side which sucks, I don’t want index.html to load in the clients browser just to forward him to login.html, the server should, in my oppinion, handle that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T03:15:09+00:00Added an answer on June 4, 2026 at 3:15 am

    It’s because express filters the request before it gets to your code. It finds the file and returns it to the browser.

    Solution is either to send an event via socket.io telling the code in user’s browser to redirect or move file into private space (outside public directory) and serve it via “fs” as CydGy suggested.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a PHP script that gets my total unread count from
I have a perl script (call it worker) installed on each node/machine (4 total)
Total noobie question here. I'm just learning Java, and studying passing arguments to functions.
Total noob to anything lower-level than Java, diving into iPhone audio, and realing from
total nubi here and i'm trying to writ an application that trackes how far
I'm trying to insert values for a node field from a custom module. The
I'm trying to get a node-set from a xsl variable for calculating. But my
For a given node I need to find the total number of sub tree
I always thought that a node in an execution plan can only be executed
I have a tree data structure that is L levels deep each node has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.