Socket
Book a DemoInstallSign in
Socket

koa-static-resolver

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-static-resolver

Koa static file resolver, dirs, default index, path replace, cache, livereload, gzip

1.0.6
latest
Source
npmnpm
Version published
Weekly downloads
117K
-2.74%
Maintainers
1
Weekly downloads
 
Created
Source

Koa Static Resolver

Koa static file resolver, dirs, default index, path replace, cache, livereload, gzip

Install

npm install koa-static-resolver --save

Usage

const Koa = require('koa');
const KSR = require('koa-static-resolver');
const app = new Koa();
app.use(KSR({
    dirs: ["./static/", "../node_modules/"],
    defaultIndex: "index.html"
}));
app.listen(8080);

cache

app.use(KSR({
    dirs: ["./static/"],
    //server cache (Memory)
    cache: {},
    //do NOT cache big size file
    cacheMaxLength: 10 * 1024 * 1024,
    //browser cache header: max-age=<seconds>
    maxAge: 600
}));

livereload

app.use(KSR({
    dirs: ["./static/"],
    livereload: '\n<script src="/livereload.js"></script>\n'
}));
//only inject to .html

gzip

app.use(KSR({
    dirs: ["./static/"],
    cache: {},
    gzip: true,
    gzipMinLength: 1024,
    gzipTypes: [".html", ".css", ".js", ".svg", ".xml"]
}));
//require headers with "Accept-Encoding": "gzip"

include/exclude

app.use(KSR({
    dirs: ["./static/"],
    include: ["include/folder", /RegExp/],
    exclude: ["exclude/folder", /RegExp/]
}));
// any files not matched include/folder will be 404 not found
// any files matched exclude/folder will be 404 not found
// support RegExp

replace

app.use(KSR({
    dirs: ["./static/"],
    replace: {
      "from_path": "to_path"
    }
}));
//when request /from_path/some_next_path/, will be replaced with /to_path/some_next_path/ to find out file path

headers

app.use(KSR({
    dirs: ["./static/"],
    headers: {
      "header_key": "header_value"
    }
}));

CHANGELOG

  • v1.0.5

    • added test case
    • added types
  • v1.0.4

    • added include/exclude match for file path
  • v1.0.3

    • fixed cache issue if maxAge=0
  • v1.0.2

    • fixed livereload

FAQs

Package last updated on 18 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.