You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

37 lines
978 B

  1. /*
  2. * Swagger UI and Specs Servers
  3. */
  4. var path = require('path');
  5. var createServer = require('http-server').createServer;
  6. var dist = path.join(__dirname, '..', '..', 'dist');
  7. var specs = path.join(__dirname, '..', '..', 'test', 'specs');
  8. var DOCS_PORT = 8080;
  9. var SPEC_SERVER_PORT = 8081;
  10. var driver = require('./driver');
  11. var swaggerUI;
  12. var specServer;
  13. module.exports.start = function (specsLocation, done) {
  14. swaggerUI = createServer({ root: dist, cors: true });
  15. specServer = createServer({ root: specs, cors: true });
  16. swaggerUI.listen(DOCS_PORT);
  17. specServer.listen(SPEC_SERVER_PORT);
  18. var swaggerSpecLocation = encodeURIComponent('http://localhost:' + SPEC_SERVER_PORT + specsLocation);
  19. var url = 'http://localhost:' + DOCS_PORT + '/index.html?url=' + swaggerSpecLocation;
  20. setTimeout(function(){
  21. driver.get(url);
  22. done();
  23. }, process.env.TRAVIS ? 20000 : 3000);
  24. };
  25. module.exports.close = function() {
  26. swaggerUI.close();
  27. specServer.close();
  28. };