How to use http-server - 10 common examples

To help you get started, we’ve selected a few http-server examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github video-dev / hls.js / tests / functional / auto / hlsjs.js View on Github external
}).catch(function(e) {
        if (++attempts >= numAttempts) {
          // reject with the last error
          reject(e);
        }
        else {
          setTimeout(attempt, interval);
        }
      });
    }
  });
}

var onTravis = !!process.env.TRAVIS;

HttpServer.createServer({
  showDir: false,
  autoIndex: false,
  root: './',
}).listen(8000, '127.0.0.1');


var browserConfig = {version : 'latest'};
if (onTravis) {
  var UA_VERSION = process.env.UA_VERSION;
  if (UA_VERSION) {
    browserConfig.version = UA_VERSION;
  }
  var UA = process.env.UA;
  if (!UA) {
    throw new Error('No test browser name.')
  }
github piotrwitek / training-management-tool / server.js View on Github external
'use strict'
const httpServer = require('http-server');

// default cache disabled
let cache = -1;
if (process.env.NODE_ENV === 'production') {
  cache = 3600;
  const msg = 'Running in production mode (caching is enabled)';
  console.log(msg);
}

const server = httpServer.createServer({
  root: './',
  cache: cache,
  robots: true,
  headers: {
    'Access-Control-Allow-Origin': '*',
    'Access-Control-Allow-Credentials': 'true'
  }
});

require('chokidar-socket-emitter')({app: server.server});

server.listen(8888);
console.log('Started http-server with chokidar-socket-emitter');
console.log('Running on localhost:8888');
github rebornix / monaco-vue / gulpfile.js View on Github external
gulp.task('simpleserver', function(cb) {
	httpServer.createServer({ root: './', cache: 5 }).listen(4000);
	// httpServer.createServer({ root: './', cache: 5 }).listen(8088);
	console.log('Server address: http://127.0.0.1:4000/');
});
github 5calls / 5calls / gulpfile.js View on Github external
gulp.task('html:serve', function (cb) {

  function alwaysServeIndex(req, res, next) {

    // Allow the development server to respond to URLs defined in the front end application.
    // Assume that any URL without a file extension can be handled by the client side code
    // and serve index.html (instead of 404).

    if(!(path.extname(req.url))) {
      req.url = "/";
    }
    next();
  }

  var server = new http_server.HttpServer({
    root: 'app/static',
    before: [connect_logger(), alwaysServeIndex]
  });
  server.listen(8000, function () {
    util.log('HTTP server started on port 8000');
    cb();
  });
});
github vuejs / vue-cli / packages / @vue / cli-service-global / __tests__ / globalServiceBuildLib.spec.js View on Github external
test('global build --target lib', async () => {
  const { stdout } = await execa(binPath, ['build', 'testLib.vue', '--target', 'lib'], { cwd })

  expect(stdout).toMatch('Build complete.')

  const distDir = path.join(cwd, 'dist')
  const hasFile = file => fs.existsSync(path.join(distDir, file))
  expect(hasFile('demo.html')).toBe(true)
  expect(hasFile('testLib.common.js')).toBe(true)
  expect(hasFile('testLib.umd.js')).toBe(true)
  expect(hasFile('testLib.umd.min.js')).toBe(true)
  expect(hasFile('testLib.css')).toBe(true)

  const port = await portfinder.getPortPromise()
  server = createServer({ root: distDir })

  await new Promise((resolve, reject) => {
    server.listen(port, err => {
      if (err) return reject(err)
      resolve()
    })
  })

  const launched = await launchPuppeteer(`http://localhost:${port}/demo.html`)
  browser = launched.browser
  page = launched.page

  const h1Text = await page.evaluate(() => {
    return document.querySelector('h1').textContent
  })
github peter-mouland / react-lego / tests / config / test-server / test-server-entry.js View on Github external
require('../../../src/config/environment');
require('../../../src/app/polyfills/node-fetch');

const HttpServer = require('http-server').HttpServer;
let openServer = new HttpServer({ root: 'compiled'});

const startLocalServers = (done) => {
  openServer.listen(process.env.PORT, 'localhost', () => {
    console.log(`Server running on port ${process.env.PORT}`);
    done()
  });
};
const stopLocalServers = (done) => {
  console.log('Closing server...');
  openServer.close(done);
};


module.exports = {
  start: startLocalServers,
  stop: stopLocalServers
github pouchdb / pouchdb / packages / node_modules / pouchdb-find / bin / dev-server.js View on Github external
function startServers(callback) {
  readyCallback = callback;
  http_server.createServer().listen(HTTP_PORT);
  var msg = 'Tests: http://127.0.0.1:' + HTTP_PORT + '/test/index.html';
  if (process.env.COUCH_HOST) {
    msg += '?couchHost=' + process.env.COUCH_HOST;
  }
  console.log(msg);
  serverStarted = true;
  checkReady();
}
github baidu / san / tool / dev.js View on Github external
}
};

let cwd = process.cwd();
let port = 8527;
let host = '0.0.0.0';
let options = {
    root: cwd,
    cache: false,
    showDir: true,
    autoIndex: true
};

let srcDir = path.resolve(__dirname, '../src');

let server = httpServer.createServer(options);

let pretest = spawn('npm', ['run', 'pretest']);
pretest.stderr.on('data', data => {
    console.log(`${data}`);
});

pretest.on('close', code => {
    server.listen(port, host, function () {
        let canonicalHost = host === '0.0.0.0' ? '127.0.0.1' : host;
        let protocol      = 'http://';
    
        logger.info(['Starting up http-server, serving '.yellow,
          server.root.cyan,
          '\nAvailable on:'.yellow
        ].join(''));
github flatiron / blacksmith / lib / commands / preview.js View on Github external
module.exports = function () {
  winston.info("Executing command "+"preview".yellow);

  var HTTPServer = require('http-server').HTTPServer;
  var httpServer = new HTTPServer({
    root: './public/'
  });

  httpServer.log = winston.info;

  httpServer.listen(process.env.PORT || process.env.C9_PORT || 8080);

  process.on('SIGINT', function() {
    winston.warn('http-server stopped.'.red);
    process.exit(0);
  });
}

http-server

A simple zero-configuration command-line http server

MIT
Latest version published 2 years ago

Package Health Score

85 / 100
Full package analysis