0.1.9 • Published 3 years ago

express-static-search v0.1.9

Weekly downloads
5
License
MIT
Repository
github
Last release
3 years ago

express-static-search

Module to get static files with deep scan of relative paths.

Install

npm install express-static-search

Example

const expressStatic = require("express-static-search");
const express = require("express");
const path = require("path");
const app = express();

const staticPath = path.join(__dirname, 'assets');

const options = {
  beforeSend: (res, fileName) => {
    if(fileName.match('is-not-static.js')) {
      return false; // return false to cancel responding of this file
    }    

    res.setHeader('Cache-Control', 'public, max-age=3600');
  }
}

app.use(expressStatic(staticPath, options));

Description

Let's say client is on /hello/world/ page and requests static-file.mp3. It is relative path, so browser sends to the server full url /hello/world/static-file.mp3. In some cases we can't set absolute path, but want to get the necessary file. This library scans every part of url to find a match. It will try to get:

  • staticPath + /hello/world/static-file.mp3
  • staticPath + /world/static-file.mp3
  • staticPath + static-file.mp3

If any file of the specified exists, then you will get it.

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

5 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago