var express = require("express")
 , url = require("url")
 , cors = require("cors")
 , app = express()
 , swagger = require("swagger-node-express")
 , db = false


var corsOptions = {
  credentials: true,
  origin: function(origin,callback) {
    if(origin===undefined) {
      callback(null,false);
    } else {
      callback(null,true);
    }
  }
};

app.use(express.json());
app.use(express.urlencoded());
app.use(cors(corsOptions));

{{#basePath}}
var subpath = express();

app.use("{{{basePath}}}", subpath);

swagger.setAppHandler(subpath);
{{/basePath}}
{{^basePath}}
swagger.setAppHandler(app);
{{/basePath}}

swagger.configureSwaggerPaths("", "api-docs", "")

var models = require("./app/models.js");

{{#apiInfo}}
{{#apis}}
var {{classname}} = require("./{{apiFolder}}/{{classname}}.js");
{{/apis}}
{{/apiInfo}}

swagger.addModels(models)
  {{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}.add{{httpMethod}}({{classname}}.{{nickname}})
  {{/operation}}{{/operations}}{{/apis}}{{/apiInfo}};

// configures the app
swagger.configure("http://localhost:8002{{basePath}}", "0.1");

//  start the server
app.listen(8002);
