github.com/qubitproducts/logspray@v0.2.14/server/swagger-ui/test/e2e/servers.js (about) 1 /* 2 * Swagger UI and Specs Servers 3 */ 4 'use strict'; 5 6 var path = require('path'); 7 var createServer = require('http-server').createServer; 8 9 var dist = path.join(__dirname, '..', '..', 'dist'); 10 var specs = path.join(__dirname, '..', '..', 'test', 'specs'); 11 var DOCS_PORT = 8080; 12 var SPEC_SERVER_PORT = 8081; 13 14 var driver = require('./driver'); 15 16 var swaggerUI; 17 var specServer; 18 19 module.exports.start = function (specsLocation, done) { 20 swaggerUI = createServer({ root: dist, cors: true }); 21 specServer = createServer({ root: specs, cors: true }); 22 23 swaggerUI.listen(DOCS_PORT); 24 specServer.listen(SPEC_SERVER_PORT); 25 26 var swaggerSpecLocation = encodeURIComponent('http://localhost:' + SPEC_SERVER_PORT + specsLocation); 27 var url = 'http://localhost:' + DOCS_PORT + '/index.html?url=' + swaggerSpecLocation; 28 29 setTimeout(function(){ 30 driver.get(url); 31 setTimeout(function() { 32 done(); 33 }, 2000); 34 console.log('waiting for UI to load'); 35 }, process.env.TRAVIS ? 20000 : 5000); 36 console.log('waiting for server to start'); 37 }; 38 39 module.exports.close = function() { 40 swaggerUI.close(); 41 specServer.close(); 42 };