const _ = require('lodash');
const jsonfile = require('jsonfile');
const path = require('path');
const express = require('express');
const app = express();

console.log(process.env.NODE_ENV);

// if (process.env.NODE_ENV !== 'production') {
//   console.log('asdasdasdasdasdasdasdasd');
//   const webpack = require('webpack');
//   const config = require('../webpack.config.dev');
//   const compiler = webpack(config);
//
//   app.use(require('webpack-dev-middleware')(compiler, {
//     noInfo: true,
//     publicPath: config.output.publicPath
//   }));
//
//   app.use(require('webpack-hot-middleware')(compiler));
// }

const networks = [
  {
    path: 'eta_3_hidden_5.json',
    hiddenNodes: 5,
    eta: 3.0,
    activation: 'Sigmoid',
    accuracy: '87%'
  },
  {
    path: 'eta_3_hidden_10.json',
    hiddenNodes: 10,
    eta: 3.0,
    activation: 'Sigmoid',
    accuracy: '90%'
  },
  {
    path: 'eta_3_hidden_20.json',
    hiddenNodes: 20,
    eta: 3.0,
    activation: 'Sigmoid',
    accuracy: '93%'
  },
  {
    path: 'eta_3_hidden_30.json',
    hiddenNodes: 30,
    eta: 3.0,
    activation: 'Sigmoid',
    accuracy: '94%'
  },
  {
    path: 'eta_.3_hidden_30.json',
    hiddenNodes: 30,
    eta: 0.3,
    activation: 'Sigmoid',
    accuracy: '82%'
  },
  {
    path: 'eta_3_hidden_20_15.json',
    hiddenNodes: '20, 15',
    eta: 3,
    activation: 'Sigmoid',
    accuracy: '93%'
  },
];

app.get('/network', (req, res) => {
  res.send(networks);
});

app.get('/network/:id', function (req, res) {
  const filename = req.params.id;

  // Make sure this is a valid name hard coded above, do not want to allow any
  // file to be returned with path.join below. Should be done better, but this
  // should be secure for now.
  const isValidPath = _.find(networks, { path: filename });
  if (!isValidPath) {
    return res.status(500).send('Network does not exist');
  }

  jsonfile.readFile(path.join(__dirname, 'json', 'networks', filename), (err, file) => {
    if (err) {
      return res.status(500).send(err);
    }
    res.send(file);
  });
});

app.get('*', (req, res) => {
  res.sendFile(path.join(__dirname, '..', 'index.html'));
});


app.listen(process.env.PORT || 3000, 'localhost', (err) => {
  if (err) {
    console.log(err);
    return;
  }

  console.log('Listening at http://localhost:3000');
});

@@ -154,47 +154,8 @@
 );%0A%0A
-console.log(process.env.NODE_ENV);%0A%0A// 
 if (
@@ -199,57 +199,8 @@
 ) %7B%0A
-//   console.log('asdasdasdasdasdasdasdasd');%0A// 
   co
@@ -229,27 +229,24 @@
 'webpack');%0A
-// 
   const conf
@@ -284,19 +284,16 @@
 .dev');%0A
-// 
   const 
@@ -320,22 +320,17 @@
 onfig);%0A
-//%0A// 
+%0A
   app.us
@@ -377,19 +377,16 @@
 iler, %7B%0A
-// 
     noIn
@@ -395,19 +395,16 @@
 : true,%0A
-// 
     publ
@@ -440,24 +440,16 @@
 ath%0A
-// 
   %7D));%0A
-//%0A// 
+%0A
   ap
@@ -500,19 +500,16 @@
 iler));%0A
-// 
 %7D%0A%0Aconst
@@ -2038,20 +2038,21 @@
 );%0A%0A
-%0Aapp.listen(
+const port = 
 proc
@@ -2075,31 +2075,40 @@
 3000
-, 'localhost', 
+;%0Aapp.listen(port, function
 (err)
- =%3E
  %7B%0A 
@@ -2157,17 +2157,158 @@
 rn;%0A  %7D%0A
-%0A
+  console.log('Node app is running on port', app.get('port'));%0A%7D);%0A%0A%0A// app.listen(process.env.PORT %7C%7C 3000, 'localhost', (err) =%3E %7B%0A//%0A//%0A// 
   consol
@@ -2352,12 +2352,15 @@
 3000');%0A
+// 
 %7D);%0A

change port