How to use the serve-static.mime function in serve-static

To help you get started, we’ve selected a few serve-static 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 collab-project / videojs-record / scripts / server.js View on Github external
import connect from 'connect';
import path from 'path';
import portscanner from 'portscanner';
import serveStatic from 'serve-static';

// Configuration for the server.
const PORT = 9999;
const MAX_PORT = PORT + 100;
const HOST = '127.0.0.1'

const app = connect();

// update mimetype
serveStatic.mime.define({'application/wasm': ['wasm']});

app.use(serveStatic(path.join(__dirname, '..')));

portscanner.findAPortNotInUse(PORT, MAX_PORT, HOST, (error, port) => {
    if (error) {
        throw error;
    }

    process.stdout.write(`Serving on http://${HOST}:${port}` + '\n\n');

    app.listen(port);
});
github mattdesl / budo / lib / middleware.js View on Github external
var logger = require('./simple-http-logger')
var urlLib = require('url')
var xtend = require('xtend')
var pushState = require('connect-pushstate')
var liveReload = require('inject-lr-script')
var urlTrim = require('url-trim')
var escapeHtml = require('escape-html')

var fs = require('fs')
var browserify = require('browserify')
var path = require('path')
var liveReloadClientFile = path.resolve(__dirname, 'reload', 'client.js')
var bundledReloadClientFile = path.resolve(__dirname, '..', 'build', 'bundled-livereload-client.js')

// Patch 'wasm' since send has not yet been updated to latest 'mime' module
serveStatic.mime.types['wasm'] = 'application/wasm'

module.exports = budoMiddleware
function budoMiddleware (entryMiddleware, opts) {
  opts = opts || {}
  var staticPaths = [].concat(opts.dir).filter(Boolean)
  if (staticPaths.length === 0) {
    staticPaths = [ process.cwd() ]
  }

  var entrySrc = opts.serve
  var live = opts.live
  var cors = opts.cors
  var handler = stacked()
  var middlewares = [].concat(opts.middleware).filter(Boolean)

  // Everything is logged except favicon.ico
github ff0000-ad-tech / wp-creative-server / routes / browse.js View on Github external
(req, res, next) => {
			const type = serveStatic.mime.lookup(req.url)
			// build paths:
			if (req.url.indexOf(utils.BUILD_FOLDER) > -1) {
				return serveStatic(global.servePath, {
					// let folders with index.html pass through
					index: false,
					// render html files as plain text
					setHeaders: (res, path) => {
						if (type === 'text/html') {
							res.setHeader('Content-Type', 'text/plain')
						}
					}
				})(req, res, next)
			} else {
				// all other assets serve static
				return serveStatic(global.servePath)(req, res, next)
			}
github GoogleChromeLabs / gulliver / app.js View on Github external
app.use((req, res, next) => {
  const path = req.url;
  req.url = asset.decode(path);
  let mime = serveStatic.mime.lookup(req.url);
  if (mime.match('image*') || req.url.includes('manifest.json')) {
    res.setHeader('Cache-Control', 'public, max-age=' + CACHE_CONTROL_EXPIRES);
  } else if (req.url === path) {
    res.setHeader('Cache-Control', 'public, max-age=' + CACHE_CONTROL_SHORT_EXPIRES);
  } else {
    // versioned assets don't expire
    res.setHeader('Cache-Control', 'public, max-age=' + CACHE_CONTROL_NEVER_EXPIRE);
  }
  staticFilesMiddleware(req, res, next);
});
github tkoenig89 / express-static-gzip / index.js View on Github external
let fs = require("fs");
let serveStatic = require('serve-static');
let sanitizeOptions = require('./util/options').sanitizeOptions;
let findEncoding = require('./util/encoding-selection').findEncoding;
let mime = serveStatic.mime;

module.exports = expressStaticGzipMiddleware;

/**
 * Generates a middleware function to serve pre-compressed files. It is build on top of serveStatic.
 * The pre-compressed files need to be placed next to the original files, in the provided `root` directory.
 * @param { string } root: directory to staticly serve files from
 * @param { expressStaticGzip.ExpressStaticGzipOptions } options: options to change module behaviour  
 * @returns express middleware function
 */
function expressStaticGzipMiddleware(root, options) {
    let opts = sanitizeOptions(options);
    let serveStaticMiddleware = serveStatic(root, opts.serveStatic || null);
    let compressions = [];
    let files = {};
github apache / metron / metron-interface / metron-alerts / scripts / alerts-server.js View on Github external
function setCustomCacheControl (res, path) {
  if (serveStatic.mime.lookup(path) === 'text/html') {
    res.setHeader('Cache-Control', 'public, max-age=10')
  }
  res.setHeader("Expires", new Date(Date.now() + 2592000000).toUTCString());
}
github apache / metron / metron-interface / metron-alerts / alerts-server-e2e.js View on Github external
function setCustomCacheControl (res, path) {
  if (serveStatic.mime.lookup(path) === 'text/html') {
    res.setHeader('Cache-Control', 'public, max-age=10')
  }
  res.setHeader("Expires", new Date(Date.now() + 2592000000).toUTCString());
}
github parcel-bundler / parcel / packages / core / parcel-bundler / src / Server.js View on Github external
const http = require('http');
const https = require('https');
const serveStatic = require('serve-static');
const getPort = require('get-port');
const serverErrors = require('./utils/customErrors').serverErrors;
const generateCertificate = require('./utils/generateCertificate');
const getCertificate = require('./utils/getCertificate');
const AnsiToHtml = require('ansi-to-html');
const logger = require('@parcel/logger');
const path = require('path');
const url = require('url');

const ansiToHtml = new AnsiToHtml({newline: true});

serveStatic.mime.define({
  'application/wasm': ['wasm'],
});

function setHeaders(res) {
  enableCors(res);
}

function enableCors(res) {
  res.setHeader('Access-Control-Allow-Origin', '*');
  res.setHeader(
    'Access-Control-Allow-Methods',
    'GET, HEAD, PUT, PATCH, POST, DELETE',
  );
  res.setHeader(
    'Access-Control-Allow-Headers',
    'Origin, X-Requested-With, Content-Type, Accept, Content-Type',
github apache / metron / metron-interface / metron-config / scripts / server.js View on Github external
function setCustomCacheControl (res, path) {
  if (serveStatic.mime.lookup(path) === 'text/html') {
    res.setHeader('Cache-Control', 'public, max-age=10')
  }
  res.setHeader("Expires", new Date(Date.now() + 2592000000).toUTCString());
}
github jimmyleray / Emendare / client / app.js View on Github external
const setCustomCacheControl = (res, path) => {
  if (serveStatic.mime.lookup(path) === 'text/html') {
    res.setHeader('Cache-Control', 'build, max-age=0')
  }
}

serve-static

Serve static files

MIT
Latest version published 2 months ago

Package Health Score

89 / 100
Full package analysis