Using Node.js and Less to dynamically select a stylesheet source depending on the subdomain

Currently, my tech stack consists of nodejs, express, jade, and less.

I have set up routing to different subdomains (for example: college1.domain.com, college2.domain.com). Each college has its own unique stylesheet. I am looking for a way to selectively load the appropriate stylesheet based on the subdomain.

Instead of passing around variables and deciding which stylesheet to load during page rendering, I am exploring the option of organizing the stylesheets into separate subdirectories. This approach would involve instructing the less-middleware to target a specific directory depending on the subdomain. Do you think this solution is feasible?

Answer №1

If you have static stylesheets, consider using nginx in front of your app server to serve the assets based on domain and/or path. This can offload asset serving from your app, allowing it to focus on other tasks and potentially improving performance.

Here is a simplified configuration example inspired by nginx documentation:

server {
  location / {
    proxy_pass http://localhost:8080;
  }

  location /stylesheets/ {
    root /path/to/your/stylesheets;
  }
}

This setup directs all requests to your app except those for files in the /stylesheets/ directory, which are served directly from the file system.

For more information, refer to the beginner's guide to nginx.

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

Tips for displaying identical tab content across various tabs using jquery or javascript

For instance, if we have tabs labeled as 1, 2, 3, 4, and 5, and a user has selected tabs 2, 3, and 4, how can we display the same content for those tabs while showing different content for the remaining ones? ...

The usage of $('').switchClass in IE8 may cause an error when the switched class includes a color property

I have the following unique css classes .swap-format{ background-color: green; } .swap-format1{ background-color: orange; } .swap-format2{ color: purple; } Using these classes, I want to create an animation on the given div <div id="swap-clas ...

Triggering an event in Angular 2 after ngFor loop completes

I am currently attempting to utilize a jQuery plugin that replaces the default scrollbar within dynamic elements in Angular 2. These elements are generated using an ngFor loop, making it impossible to directly attach jQuery events to them. At some point, ...

Utilizing Sinon to Stub Chained "whereIn" Functions in Objection.js

Need help stubbing a chained knex query with Sinon. Here is the query: const result = await TableModel .query() .whereIn('id', idList) .whereIn('value', valueList); Usually, I use a custom helper function that stubs each method ...

Tips on storing information within a Vue instance

Seeking a simple solution, all I need is to save data retrieved after an AJAX post in the Vue instance's data. See below for my code: const VMList = new Vue({ el: '#MODAL_USER_DATA', data: { user: []//, //userAcc: [] }, met ...

Error message encountered in PHP due to an undefined index

My goal is to add items from a form to a table named products. The form layout can be seen here: https://i.stack.imgur.com/f9e08.png The "Add more suppliers: +" link adds a new row to the form when clicked. The corresponding script for this action is as ...

Is it possible for an AJAX request to return both HTML data and execute callback functions simultaneously?

Is it possible to update the content of an HTML div and call a JavaScript function with specific parameters obtained through AJAX after the completion of the AJAX request, all within a single AJAX call? ...

The data from callbackurl could not be received

I've successfully integrated the 3DS payment system using the Iyzipay Node.js client. My API stack consists of Node.js with Express, while my UI is built with React.js. My current issue revolves around not receiving data from a callback. Let me walk ...

Using a vanilla JS object as a prop for a child component

I have created a custom Message class in my application to handle incoming messages, which is defined in message.js. Within message.js, I've implemented two classes: Message and EventEmit. The render function in my Message class requires passing an E ...

Having trouble with the functionality of the jQuery `has()` method?

Consider the following HTML code snippet: <div class="comment"> <span class="test">some content here</span> <p>Lorem ipsum</p> </div> <div class="comment"> <p>Lorem ipsum</p> </div> The ob ...

Vue and Summernote issue: Model content doesn't display in form when loaded from database

I am having an issue with my form that uses the Summernote wysiwyg editor multiple times. When I fill out the form, everything works correctly - the model is updated, content is displayed, and the data is saved to the database. However, when I try to edit ...

What's the optimal method for determining a user's country in Next.js and Node.js?

What's the most efficient way to retrieve a user's country in a Next.js app for quick loading? I plan to use this information to determine which scripts are loaded using next/script. I've looked into node-geoip and fast-geoip, but despite t ...

Whenever I try to send an email in Node.js, I encounter 404 errors. Additionally,

I have an Angular application with a form that makes AJAX requests. Emailing works fine, but no matter what I set the response to, I get an error for the path '/send'. I assume Node.js expects the path '/send' to render a template or da ...

Expressjs throwing a 403 forbidden error while trying to make a post request

Hey everyone, I'm currently experiencing an issue while trying to submit a new form, and I keep encountering the 403 error below: Error: Forbidden at Object.exports.error (/Users/mark/Dropbox/Programming/mine/node/botappv2/node_modules/express/node_m ...

Executing multiple calls with Angular's $http service and then resolving them within a loop using underscore

I am facing an issue while trying to fetch multiple data from $http inside _.each function and display the combined data in $scope.tasksData. The problem I encountered is that _.each is being executed later, causing it to return null first. Can someone pl ...

find the middle element in the Vue array

Currently in the process of developing a custom Vue carousel component, I have utilized some code snippets from this resource: link My goal right now is to enhance the slider with additional navigation bullets. However, due to the justify-content:center p ...

Tips for applying stroke and shadow effects specifically when the mouse is moving over a canvas:

How can we create a shadow and stroke effect for circles drawn using HTML canvas only during mouse hover? I have two circles and would like to add a shadow and stroke effect when the mouse hovers over them. However, the issue is that once the mouse moves ...

Implementing a translucent overlay onto a specific HTML section using sidebar.js/jQuery

Searching for a way to enhance the functionality of my website using Sidebar.js, I came across an interesting feature on hypebeast.com. When you click on the three-bar icon, the main container section's opacity changes. How can I achieve this effect? ...

The issue of ExpressionChangedAfterItHasBeenCheckedError is a common problem faced by Angular

I have implemented a component loading and an interceptor to handle all requests in my application. The loading component is displayed on the screen until the request is completed. However, I am encountering an error whenever the component inside my router ...

Changing the MIME type of a JavaScript file in a Jade/Pug environment to text/html

Hi there, I've been experimenting with jade/pug to get my node.js backend to render the front-end pages. However, I'm facing some issues when trying to include JavaScript for certain functionalities. Whenever I try to load it, I encounter this er ...