Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

41 řádky
1.1 KiB

  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 headers = {
  12. 'Access-Control-Allow-Origin': '*',
  13. 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept'
  14. };
  15. var swaggerUI;
  16. var specServer;
  17. module.exports.start = function (specsLocation, done) {
  18. swaggerUI = createServer({ root: dist, headers: headers });
  19. specServer = createServer({ root: specs, headers: headers });
  20. swaggerUI.listen(DOCS_PORT);
  21. specServer.listen(SPEC_SERVER_PORT);
  22. var swaggerSpecLocation = encodeURIComponent('http://localhost:' + SPEC_SERVER_PORT + specsLocation)
  23. var url = 'http://localhost:' + DOCS_PORT + '/index.html?url=' + swaggerSpecLocation;
  24. setTimeout(function(){
  25. driver.get(url);
  26. done();
  27. }, process.env.TRAVIS ? 20000 : 3000);
  28. };
  29. module.exports.close = function(){
  30. swaggerUI.close();
  31. specServer.close();
  32. }