Socket
Book a DemoInstallSign in
Socket

koa-public-path-static

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-public-path-static

koa static server with configurable publickPath

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source
yarn add koa-public-path-static

What it is about?

So, I didn't find koa static server with configurable publicPath and ability to pass request to the next middleware, if file is not found, and wrote my own.

Exmaple

Say, you have the following file structure:

projectroot/assets/fox.png
projectroot/build/font.woff
projectroot/public/license.pdf

And you want that files to be accesible via urls:

https://yourawesomeproject.domain/assets/font.woff
https://yourawesomeproject.domain/assets/license.pdf
https://yourawesomeproject.domain/assets/fox.png

And, for some reasons, you use koa, not express...

With koa-public-path-static it is as simple as that:

const path = require('path');
const serve = require('koa-public-path-static');

const assetsDir = path.resolve(__dirname, './assets');
const buildDir = path.resolve(__dirname, './build');
const publicDir = path.resolve(__dirname, './public');

app.use(serve(assetsDir));
app.use(serve({
  path: buildDir,
  publicPath: '/assets'
}));
app.use(serve({
  path: publicDir,
  publicPath: '/assets'
}));

FAQs

Package last updated on 17 May 2017

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