Jade - a set of base catalog depending on the environment

I have a jade page, and the first thing I do is set a variable that defines the base directory used by all links.

if ! base base = '/klog/' // base = '/website-clear/klog/' 

This is valid for the github page, so every time I transfer the page to html, I must remember to change the database, and then change it again for local editing.

There must be a better way to do this. Currently, I think there is an unprocessed file in the local copy that includes the database - but is it really necessary?

What is the best way to deal with this problem?

+8
javascript pug
source share
1 answer

A more robust solution would check for environment variables. Install NODE_ENV=production on the production server and do not install it on the dev server.

Then in your jade pattern visualize different paths if an environment variable exists.

 if 'production' == process.env.NODE_ENV - base = '/website-clear/klog/' 

or

 - base = ( 'production' == process.env.NODE_ENV ? '/website-clear/klog/' : '/klog' ); 
+10
source share

All Articles