Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jade - set base directory depending on environment

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

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

This is actually for a github page, so every time I render the page to html, I have to remember to change the base, and then change it back again for local editing.

There must be a better way of doing it. Currently I am thinking to have an untracked file in the local copy, that includes the base - but is that really necessary?

What is the best way to handle this issue?

like image 857
Billy Moon Avatar asked Sep 16 '12 20:09

Billy Moon


1 Answers

A more robust solution would be checking for environment variables. Have NODE_ENV=production set on the production server, and do not set it on the dev server.

Then in your jade template, render different paths if the environment variable exists.

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

or

- base = ( 'production' == process.env.NODE_ENV ? '/website-clear/klog/' : '/klog' );
like image 153
Mike Causer Avatar answered Nov 08 '22 02:11

Mike Causer