1.0.0 • Published 8 years ago

bluegate-static v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

BlueGate Static

Build Status Coverage Status Dependency Status Known Vulnerabilities

Serve static assets in a BlueGate application.

This module is intended for small amounts of files, such as CSS-files and images. The list of available paths is generated on startup. A single file read is executed when requesting a file. This has advantages for performance and security, but is not suitable for many files or user uploads.

Installation

Install using npm install bluegate-static

Quick example

Serve static files in /assets folder.

var BlueGate = require('bluegate');
var app = new BlueGate();
app.listen(8080);

require('bluegate-static')(app);

Custom options

The following options can be provided:

  • filepath is the basepath on the local file system.
  • webpath is the basepath on the website.
  • files is the pattern, parsed by the globby module.

All files are served on "/webpath/relativepath", where "relativepath" is the path on the local filesystem without the path provided infilepath.

Example to serve files in "css", "js" and "images" directories.

var BlueGate = require('bluegate');
var app = new BlueGate();
app.listen(8080);

require('bluegate-static')(app, {
  filepath: '',
  webpath: '/',
  files: '{css,js,images}/**/*.{css,js,png,gif,jpg,jpeg,svg,woff,woff2,eot,ttf}'
});

MIME-types

This module includes a list of common built-in MIME-types. You can however specify extra MIME-types in the options.

require('bluegate-static')(app, {
  mimeTypes: {test: 'application/x-test'}
});
1.0.0

8 years ago