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 7592451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:54:35+00:00 2026-05-30T20:54:35+00:00

In Express under Node.js, I’d like to inspect a request under a specific path

  • 0

In Express under Node.js, I’d like to inspect a request under a specific path (say, /restricted) and if it is acceptable, have the request be handled by the static provider, which handles the caching headers etc.

If I simply use app.get('/restricted/:file', ...) and then use res.sendfile to send the static file if approved, it will ignore any caching headers and always send the file.

I can’t use a blanket logged-in check because different users should only get different files.

What is the best way to implement this?

  • 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-05-30T20:54:36+00:00Added an answer on May 30, 2026 at 8:54 pm
    var express = require("express");
    var app = express.createServer();
    
    var staticMiddleware = express.static(__dirname + "/public");
    
    app.get("/restricted/:file", function(req, res, next) {
      var authorized = true;
      //Compute authorization appropriately here
      if (authorized) {
        staticMiddleware(req, res, next);
      } else {
        res.send(401);
      }
    });
    app.listen(3456);
    

    This will use the static middleware when appropriate including all of its functionality. Otherwise you can handle unauthorized requests as appropriate.

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

Sidebar

Related Questions

I have an ASP.NET MVC 3 .NET application under Visual web developer Express 2010.
I'm having a problem with Express under Node.js. I'm trying to use sessions to
I'm in the process of learning Node.js and have been playing around with Express
I have a program written in VB 2010 express under windows xp which does
I have an application developted with Visual C++ 2008 Express Edition under Windwos XP,
I'm beginning under NodeJS/Express and I'm facing the following problem (I probably didn't get
I'm doing some R&D on Node.js and so far I like it, I'm just
In SQL Server Management Studio Express 2008 options, under source control the only available
I have started initially with VC++ 2008 Express. I've noticed that GCC becomes kind
I have a C# project that I have created in Visual Studio Express 2010.

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.