var express = require('express');
var server = express();
var stylus = require('stylus');
var nib = require('nib');
var morgan = require('morgan');
var grid = require('./scripts/gridDB');

var env = process.env.NODE_ENV || 'development';

function isDev() {
  return env === 'development';
}

function compile(str, path) {
  return stylus(str)
    .set('filename', path)
    .use(nib())
}

server.set('view engine', 'pug');

server.use(morgan(isDev() ? 'dev' : 'short'));
server.use(stylus.middleware({
  src: __dirname + '/public',
  compile: compile,
}))


if (isDev()) {
  const httpProxy = require('http-proxy');
  const proxy = httpProxy.createProxyServer();

  server.get('/dist/*', (req, res) => {
    proxy.web(req, res, { target: 'http://localhost:8080' });
  });
}

server.use(express.static('public'));

server.get('/', (req, res) => {
  res.render('index');
});

server.get('/kern', (req, res) => {
    grid().then(function(arr) {
        res.json(arr);
    });
});

server.listen(3000, function () {
  console.log("Listening on port 3000");
});

@@ -968,24 +968,61 @@
    %7D);%0A%7D);%0A%0A
+var port = process.env.PORT %7C%7C 3000;%0A
 server.liste
@@ -1023,20 +1023,20 @@
 .listen(
-3000
+port
 , functi
@@ -1057,17 +1057,17 @@
 ole.log(
-%22
+%60
 Listenin
@@ -1080,13 +1080,16 @@
 ort 
-3000%22
+$%7Bport%7D%60
 );%0A%7D

Make port dynamic