Skip to content
This repository has been archived by the owner on Sep 16, 2020. It is now read-only.
/ static Public archive

A servem middleware used to serve static files from a specified directory.

License

Notifications You must be signed in to change notification settings

srvem/static

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@srvem/static

A Srvem middleware used to serve static files from a specified directory.

Installation

npm install --save @srvem/app @srvem/static

Example

import { Srvem } from '@srvem/app'
import { SrvStatic } from '@srvem/static'

// create a Srvem app
const app: Srvem = new Srvem()

// use SrvStatic middleware
app.use(new SrvStatic('public')) // host the /public directory

// listen on port 3000
app.server.listen(3000)

API

import { Context, MiddlewareBlueprint } from '@srvem/app'

/**
 * Used to serve static files from a directory.
 */
declare class SrvStatic extends MiddlewareBlueprint {
  /**
   * Root of the served directory.
   */
  baseDirectory: string

  /**
   * Default index file name for directory requests
   */
  indexName: string

  /**
   * Constructs the SrvStatic middleware.
   *
   * @param baseDirectory Root of the served directory
   * @param indexName Default index file name for directory requests
   */
  constructor(baseDirectory?: string, indexName?: string)

  /**
   * Attempts to serve GET requests.
   *
   * @param ctx The Context
   */
  main(ctx: Context): Promise<void>
}

See Also

  • @srvem/app - The core package of Srvem (contains a class used to construct a Srvem app).
  • @srvem/router - A Srvem middleware used to develop routers and server APIs with asynchronous request handlers.

Credits

Kaleab S. Melkie <[email protected]>

License

MIT License
Copyright © 2017 srvem

Made with ❤ in Addis Ababa.