Skip to content

How to serve static files with a folder different for each domain #5076

Answered by OmBayus
ghost asked this question in Q&A
Discussion options

You must be logged in to vote

Yes you can do that

Try this codes;

const handler1 = express.static(`resources_folder1`);
const handler2 = express.static(`resources_folder2`);


app.use('/resources', (req,res,next)=>{
    const origin = req.get('host')
    if(origin === "localhost"){
        handler1(req, res, next)
    }
    else if(origin === "127.0.0.1"){
        handler2(req, res, next)
    }
})

Replies: 6 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@ghost
Comment options

Answer selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
1 participant
Converted from issue

This discussion was converted from issue #5076 on December 25, 2022 18:50.