'use strict';

const express = require('express');
const router = express.Router();

const controller = require('./controller');

// middleware to allow CORS
router.use((req, res, next) => {
  var origin = req.headers.origin;

  res.setHeader('Access-Control-Allow-Origin', "*");
  res.header('Access-Control-Allow-Methods', 'GET, POST, DELETE');
  res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
  res.header('Access-Control-Allow-Credentials', true);
  next();
});

router.post('/', controller.createNetwork);

// specify `?orgName` & `?domain`
router.get('/peer/:peerName', controller.exportPeerCertificates);

// specify `?channel` & `?profileName`
router.post('/anchor-peer-file', controller.createAnchorPeerFile);

// specify `?channel` & `?profileName`
router.post('/channel', controller.createChannel);

// specify `?fileName`
router.post('/cryptogen-generate', controller.runCryptogen);

// generates by reading filesystem
router.post('/docker-compose', controller.createDockerCompose);

// specify `?profileName`
router.post('/genesis-block', controller.createGenesisBlock);

// specify `?fileName`
router.get('/yaml-file', controller.getYamlFile);
router.post('/yaml-file', controller.createYamlFile);

module.exports = router;

@@ -536,23 +536,42 @@
 k);%0A%0A// 
-specify
+export peer credentials%0A//
  %60?orgNa
@@ -652,31 +652,122 @@
 cates);%0A%0A// 
-specify
+Retrieve yaml file as JSON%0Arouter.get('/yaml-file', controller.getYamlFile);%0A%0A// Generate files%0A//
  %60?channel%60 
@@ -850,27 +850,18 @@
 rFile);%0A
-%0A
 //
- specify
  %60?chann
@@ -932,27 +932,18 @@
 annel);%0A
-%0A
 //
- specify
  %60?fileN
@@ -1008,17 +1008,16 @@
 togen);%0A
-%0A
 // gener
@@ -1107,27 +1107,18 @@
 mpose);%0A
-%0A
 //
- specify
  %60?profi
@@ -1191,19 +1191,10 @@
 k);%0A
-%0A
 //
- specify
  %60?f
@@ -1206,58 +1206,8 @@
 me%60%0A
-router.get('/yaml-file', controller.getYamlFile);%0A
 rout
@@ -1257,16 +1257,17 @@
 File);%0A%0A
+%0A
 module.e

refactor routes order