Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

217
Views
Serve different asset paths based on express js

I have a set of routes on express which are brands. Id like to serve 2 asset directories to each of these brands. One public/static for all brand routes and then everything thats under public/brands/brandName.

Is this possible ? I have something like this which seems to work but only for the first /brandName i request.

var express = require('express');
var app = express();
var path = require('path');

app.get('/brands/:brand', function (req, res) {

  app.use(express.static(path.join(__dirname, 'public/brands/' + req.params.brand)));

  res.sendFile(__dirname + '/public/static/index.html');
});

app.listen(process.env.PORT || 3000, function () {
  console.log('listening on port 3000!');
});

app.use(express.static(path.join(__dirname, 'public/static')));

module.exports = app;
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

This should do the trick;

app.use('/brands', express.static(path.join(__dirname, 'public/brands/')));
app.use('/static', express.static(path.join(__dirname, 'public/static/')));

app.get('/brands/:brand', function (req, res) {
    res.sendFile(__dirname + '/public/static/index.html');
});
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!