const http = require('http');
const path = require('path');
const fs = require('mz/fs');
const serveStatic = require('serve-static');
const compression = require('compression');
const express = require('express');
const app = express();
const adaro = require('adaro');
const removeHash = require('./middlewares/remove-hash');

const production = process.env.NODE_ENV === 'production';
const port = process.env.PORT || 3000;
const staticPath = './static';
const swPath = './service-worker.js';
const templatePath = './templates';

const options = {
  cache: production ? true : false,
  whitespace: production ? false : true,
  helpers: [
    require('./helpers/add-hash')
  ]
};

app.use(removeHash);
app.use(compression());
app.use('/static', serveStatic(staticPath, {
  maxAge: production ? (365 * 24 * 60 * 60 * 1000) : 0
}));

app.use('/sw.js', serveStatic(swPath, {
  maxAge: 0 // never cache the service-worker
}));

app.engine('dust', adaro.dust(options));
app.set('view engine', 'dust');
app.set('views', templatePath);

app.get('/', (req, res) => {
  res.status(200).render('sections/home', {
    title: 'Portfolio',
    styles: [path.join(staticPath, 'styles', 'ptf.css')],
    scripts: [path.join(staticPath, 'scripts', 'bundle.js')]
  });
});

app.get('/check', res => res.send('server ok.'));

http.createServer(app).listen(port, () => {
  console.log(`Portfolio running on http://localhost:${port}`);
})

@@ -1245,24 +1245,972 @@
 %0A  %7D);%0A%7D);%0A%0A
+app.get('/cv', (req, res) =%3E %7B%0A  res.status(200).render('sections/cv', %7B%0A    title: 'Portfolio',%0A    styles: %5Bpath.join(staticPath, 'styles', 'ptf.css')%5D,%0A    scripts: %5Bpath.join(staticPath, 'scripts', 'bundle.js')%5D%0A  %7D);%0A%7D);%0A%0Aapp.get('/activities', (req, res) =%3E %7B%0A  res.status(200).render('sections/activities', %7B%0A    title: 'Portfolio',%0A    styles: %5Bpath.join(staticPath, 'styles', 'ptf.css')%5D,%0A    scripts: %5Bpath.join(staticPath, 'scripts', 'bundle.js')%5D%0A  %7D);%0A%7D);%0A%0Aapp.get('/projects', (req, res) =%3E %7B%0A  res.status(200).render('sections/projects', %7B%0A    title: 'Portfolio',%0A    styles: %5Bpath.join(staticPath, 'styles', 'ptf.css')%5D,%0A    scripts: %5Bpath.join(staticPath, 'scripts', 'bundle.js')%5D%0A  %7D);%0A%7D);%0A%0Aapp.get('/learning', (req, res) =%3E %7B%0A  res.status(200).render('sections/learning', %7B%0A    title: 'Portfolio',%0A    styles: %5Bpath.join(staticPath, 'styles', 'ptf.css')%5D,%0A    scripts: %5Bpath.join(staticPath, 'scripts', 'bundle.js')%5D%0A  %7D);%0A%7D);%0A%0A
 app.get('/ch

add other routes, will do dry later