Questions tagged [koa-static]

Static file serving middleware for koa with directory, rewrite and index support

Installation

$ npm install koa-static-server

API

var koa = require('koa')
var app = koa()
app.use(require('koa-static-server')(options))

Options

  • rootDir {string} directory that is to be served
  • rootPath {string} optional rewrite path, defaults to "/"
  • notFoundFile {string} optional default file to serve if requested static is missing
  • log {boolean} request access log to console
  • last {boolean} don't execute any downstream middleware. defaults to true
  • maxage Browser cache max-age in milliseconds. defaults to 0
  • hidden Allow transfer of hidden files. defaults to false
  • gzip Try to serve the gzipped version of a file automatically when gzip is ---supported by a client and if the requested file with .gz extension exists. defaults to true.
6 questions
11
votes
2 answers

Why can't I serve static files from a Koa router?

Why in the following case does koa-static fail to work with koa-router? const Koa = require("koa") const serve = require("koa-static") const Router = require("koa-router") const app = new Koa() const router = new Router() // fails with 404...…
ChaseMoskal
  • 7,151
  • 5
  • 37
  • 50
1
vote
0 answers

Serving front-end web-application from a type-script based KOA server cannot resolve CSS and JS files

I am trying to serve a front-end web-application from a type-script based KOA server. The index.html (HTML) renders fine from the public folder when i hit a full url till index.html (http://localhost:3000/ui/index.html). however the local js/css…
Tarun Patel
  • 243
  • 9
  • 22
1
vote
2 answers

Apidoc - Node.js doesn't show me @apiName

I have a problem with my documentation of API. I want to make documentation, but @apiName doesn't appear... I tried to add @appVersion, but it didn't work. This is my documentation /** * @api {post} /createBook * @apiGroup Books * @apiName…
David Kadlcek
  • 456
  • 1
  • 4
  • 18
0
votes
0 answers

how to koa-mount multiple koa-static serve()

As a junior developer i'm facing a problem with koa-static. I have two graphiQL playground on /private and /admin. The documentation was koa-static serve() from an index.html file (same doc for…
0
votes
1 answer

How can I do a conditional router in Koa?

Currently, I am serving an HTML file and it works fine. (I am using koa-mount and koa-static to serve an index file under the docs directory.) app.use(mount('/docs', serve('docs'))) How can I do a conditional router in a different environment…
SPG
  • 6,109
  • 14
  • 48
  • 79
0
votes
0 answers

How do I make a koa server work with a SPA that has react router

Ok, I have a project and in the past I made a koa SPA (using koa-static) because I needed it to run the page on heroku, the thing is that now I have react-router in my page and it works half fine. For example using the buttons that I have in the…