Express Static variable folder

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Express Static variable folder



I have two folders, each folder contains a different theme for each store.



/angularApp_v1



/angularApp_v2



I have a middleware to find out which folder should be served when a request enters. Example:



-- www.storev1.com should go to /angularApp_v1



-- www.storev2.com should go to /angularApp_v2



Whats the best way to route each domain to their correct express.static folder.?



EDIT:


var storeMiddlware = function(req, res, next)
getStoreTheme(req.hostname, function(response)
req.storeTheme = response.theme;

)

app.use(storeMiddleware);
app.use('/', express.static(req.storeTheme));



where req.storeTheme = the folder (angularApp_v1 or angularApp_v2)



SOLVED: using 'serve-static'


var themeAssests =
'v1': serveStatic('angularApp_v1'),
'v2': serveStatic('angularApp_v2')


app.use("/", function(req, res, next)
themeAssests[req.storeTheme](req, res, next);
)





Also u have two different hostname, one is storev1 and other is storev2, so they will be running on different ports right, which means different node servers
– zenwraight
Aug 8 at 2:56





Then there is no need to specify two different folder, unless there were two different folders for one application.
– zenwraight
Aug 8 at 2:56





@zenwraight each folder is a theme, and the store can choose which theme. So they need to be hosted on the same node server. Theres a variable on the database that decides which folder should be served for an individual store
– Betoo
Aug 8 at 3:21





The folder can change dynamically so theres a middleware to check DB and get what theme the store is using.
– Betoo
Aug 8 at 3:23





@zenwraight I updated my question to include the middleWare, and an example of what I want to acomplish. express.static(req.storeTheme) is not possible because req.storeTheme isnt defined until the request is made.
– Betoo
Aug 8 at 3:27




1 Answer
1



For anyone with this problem, view my question I included the solution over there.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard