// List module dependancies
var express = require('express');
var bodyParser = require('body-parser');
var db = require('./models');
var http = require('http');
var epilogue = require('epilogue');

// Init express app
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

// test login authentification
db.sequelize
  .authenticate()
  .then(function(success) {
    console.log('Connection has been established successfully.');
  })
  .catch(function (err) {
    console.log('Unable to connect to the database:', err);
  });

// Init Epilogue
epilogue.initialize({
  app: app,
  sequelize: db.sequelize
});

var baseapiurl = '/api/v0/'

// Create REST resources
var taxonResource = epilogue.resource({
  model: db.taxon,
  endpoints: ['taxon','taxon/:id'].map(function(x){return(baseapiurl+x)});
});

var datasetResource = epilogue.resource({
  model: db.dataset,
  endpoints: ['dataset','dataset/:id'].map(function(x){return(baseapiurl+x)});
});

var interactionResource = epilogue.resource({
  model: db.interaction,
  endpoints: ['interaction','interaction/:id'].map(function(x){return(baseapiurl+x)});
});

var itemResource = epilogue.resource({
  model: db.item,
  endpoints: ['item','item/:id'].map(function(x){return(baseapiurl+x)});
});

var networkResource = epilogue.resource({
  model: db.network,
  endpoints: ['network','network/:id'].map(function(x){return(baseapiurl+x)});
});

// Sync database with new models
db.sequelize.sync({force:true});

// start server
var port = process.env.PORT || 3000;
server = http.createServer(app);
server.listen(port);

@@ -679,16 +679,155 @@
 i/v0/'%0A%0A
+function endpointize(endpoints, baseurl) %7B%0A    return endpoints.map(%0A        function(e)%7B%0A            return(baseurl+e)%0A        %7D%0A    )%0A%7D%0A%0A
 // Creat
@@ -915,16 +915,28 @@
 points: 
+endpointize(
 %5B'taxon'
@@ -952,48 +952,9 @@
 id'%5D
-.map(function(x)%7Breturn(baseapiurl+x)%7D);
+)
 %0A%7D);
@@ -1031,16 +1031,28 @@
 points: 
+endpointize(
 %5B'datase
@@ -1072,48 +1072,9 @@
 id'%5D
-.map(function(x)%7Breturn(baseapiurl+x)%7D);
+)
 %0A%7D);
@@ -1159,16 +1159,28 @@
 points: 
+endpointize(
 %5B'intera
@@ -1208,48 +1208,9 @@
 id'%5D
-.map(function(x)%7Breturn(baseapiurl+x)%7D);
+)
 %0A%7D);
@@ -1281,16 +1281,28 @@
 points: 
+endpointize(
 %5B'item',
@@ -1316,48 +1316,9 @@
 id'%5D
-.map(function(x)%7Breturn(baseapiurl+x)%7D);
+)
 %0A%7D);
@@ -1395,16 +1395,28 @@
 points: 
+endpointize(
 %5B'networ
@@ -1436,48 +1436,9 @@
 id'%5D
-.map(function(x)%7Breturn(baseapiurl+x)%7D);
+)
 %0A%7D);

Use a function to create endpoints