How to use the mime.default_type function in mime

To help you get started, we’ve selected a few mime 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 thgh / rollup-plugin-serve / src / index.js View on Github external
function serve (options = { contentBase: '' }) {
  if (Array.isArray(options) || typeof options === 'string') {
    options = { contentBase: options }
  }
  options.contentBase = Array.isArray(options.contentBase) ? options.contentBase : [options.contentBase || '']
  options.port = options.port || 10001
  options.headers = options.headers || {}
  options.https = options.https || false
  options.openPage = options.openPage || ''
  mime.default_type = 'text/plain'

  const requestListener = (request, response) => {
    // Remove querystring
    const urlPath = decodeURI(request.url.split('?')[0])

    Object.keys(options.headers).forEach((key) => {
      response.setHeader(key, options.headers[key])
    })

    readFileFromContentBase(options.contentBase, urlPath, function (error, content, filePath) {
      if (!error) {
        return found(response, filePath, content)
      }
      if (error.code !== 'ENOENT') {
        response.writeHead(500)
        response.end('500 Internal Server Error' +
github beakerbrowser / beaker-core / lib / mime.js View on Github external
const through2 = require('through2')
const identifyFiletype = require('identify-filetype')
const mime = require('mime')
const path = require('path')
const textextensions = require('textextensions')
const binextensions = require('binary-extensions')
const concat = require('concat-stream')

// config default mimetype
mime.default_type = 'text/plain'
const TEXT_TYPE_RE = /^text\/|^application\/(javascript|json)/

const identify = exports.identify = function (name, chunk) {
  // try to identify the type by the chunk contents
  var mimeType
  var identifiedExt = (chunk) ? identifyFiletype(chunk) : false
  if (identifiedExt) { mimeType = mime.lookup(identifiedExt) }
  if (!mimeType) {
    // fallback to using the entry name
    mimeType = mime.lookup(name)
  }

  // hackish fix
  // the svg test can be a bit aggressive: html pages with
  // inline svgs can be falsely interpretted as svgs
  // double check that
github godaddy / warehouse.ai / lib / routes / assets.js View on Github external
/* eslint no-bitwise: 0*/
'use strict';

const mime = require('mime');

//
// As our intention is to primary serve JS builds, this should be our default
// type when the mime lookup fails to find something fruitful.
//
mime.default_type = 'text/javascript';

module.exports = function (app) {
  const spec = app.spec;

  /**
   * @swagger
   *
   * definitions:
   *   Assets:
   *     type: object
   *     properties:
   *       files:
   *         type: array
   *         items:
   *           type: string
   */
github beakerbrowser / beaker / app / lib / mime.js View on Github external
import through2 from 'through2'
import identifyFiletype from 'identify-filetype'
import mime from 'mime'
import path from 'path'
import textextensions from 'textextensions'
import binextensions from 'binary-extensions'
import concat from 'concat-stream'
import {cbPromise} from './functions'

// config default mimetype
mime.default_type = 'text/plain'
const TEXT_TYPE_RE = /^text\/|^application\/(javascript|json)/

export function identify (name, chunk) {
  // try to identify the type by the chunk contents
  var mimeType
  var identifiedExt = (chunk) ? identifyFiletype(chunk) : false
  if (identifiedExt) { mimeType = mime.lookup(identifiedExt) }
  if (!mimeType) {
    // fallback to using the entry name
    mimeType = mime.lookup(name)
  }

  // hackish fix
  // the svg test can be a bit aggressive: html pages with
  // inline svgs can be falsely interpretted as svgs
  // double check that
github beakerbrowser / hashbase / lib / helpers.js View on Github external
var promisify = require('es6-promisify')
var through2 = require('through2')
var identifyFiletype = require('identify-filetype')
var mime = require('mime')

// config default mimetype
mime.default_type = 'text/plain'

exports.promisify = promisify
exports.promisifyModule = function (module, methods) {
  for (var m of methods) {
    module[m] = promisify(module[m], module)
  }
}

exports.pluralize = function (num, base, suffix = 's') {
  if (num === 1) {
    return base
  }
  return base + suffix
}

exports.makeSafe = function (str) {
github beakerbrowser / beaker / app / background-process / networks / dat.js View on Github external
var dbPath // path to the hyperdrive folder
var db // level instance
var archiveMetaDb // archive metadata sublevel
var subscribedArchivesDb // subcribed archives sublevel
var ownedArchivesDb // owned archives sublevel
var drive // hyperdrive instance
var wrtc // webrtc instance

var archives = {} // key -> archive
var swarms = {} // key -> swarm
var ownedArchives = new Set() // set of owned archives
var subscribedArchives = new Set() // set of current subscriptions
var archivesEvents = new EventEmitter()

// config default mimetype
mime.default_type = 'text/plain'

// exported API
// =

export function setup () {
  // open databases
  dbPath = path.join(app.getPath('userData'), 'Hyperdrive')
  mkdirp.sync(path.join(dbPath, 'Archives')) // make sure the folders exist
  db = level(dbPath)
  archiveMetaDb = subleveldown(db, 'archive-meta', { valueEncoding: 'json' })
  subscribedArchivesDb = subleveldown(db, 'subscribed-archives', { valueEncoding: 'json' })
  ownedArchivesDb = subleveldown(db, 'owned-archives', { valueEncoding: 'json' })
  drive = hyperdrive(db)

  // watch archives for FS changes
  var watcher = chokidar.watch(path.join(dbPath, 'Archives'), { persistent: true, cwd: path.join(dbPath, 'Archives') })
github rkendall / reffix / lib / utils.js View on Github external
restoreJsFileExtension: function(filePath) {
		mime.default_type = 'none';
		if (path.extname(filePath) === '') {
			filePath += '.js';
		} else {
			// Check if .* is a valid extension or part of the filename
			var mimeType = mime.lookup(filePath);
			if (mimeType === 'none') {
				filePath += '.js';
			}
		}
		return filePath;
	},
github OnceDoc / onceio / onceio.js View on Github external
return tar;
  }
};

//Shortcuts
var define = Object.defineProperty;

//Mapping
var CHARS = '0123456789abcdefghijklmnopqrstuvwxyz'.split('');



/*
change default type
*/
mime.default_type = ''


/*
* Define and Export OnceIO
*/
var OnceIO = module.exports = function(options) {

  var self = {};

  var SessionStore;

  /*****************Web module definitions*************/
  /*
  Configurations
  */
  var Settings = {
github solid / node-solid-server / lib / handlers / patch.js View on Github external
module.exports = handler

var mime = require('mime')
mime.default_type = 'text/turtle'
var fs = require('fs')
var $rdf = require('rdflib')
var debug = require('../debug').handlers
var utils = require('../utils.js')
var error = require('../http-error')
const waterfall = require('run-waterfall')

function handler (req, res, next) {
  req.setEncoding('utf8')
  req.text = ''
  req.on('data', function (chunk) {
    req.text += chunk
  })

  req.on('end', function () {
    patchHandler(req, res, next)
github spirit-js / spirit / src / http / response-class.js View on Github external
const mime = require("mime")
mime.default_type = undefined

const utils = require("../http/utils")

const is_Response = (obj) => {
  if (obj !== null && typeof obj === "object") {
    return obj instanceof Response
  }
  return false
}

/*
 * Response is for making response maps
 * with chainable helper functions
 */

class Response {