Giter VIP home page Giter VIP logo

koa2-vhost's Introduction

koa2-vhost

Koa2 middleware to map hostnames to static folders (https://www.npmjs.com/package/koa2-vhost)

Install package

npm i --save koa2-vhost

Example of usage

const Koa = require('koa')
const path = require('path')
const vhost = require('koa2-vhost')
const STATIC_DIR = path.join(__dirname, process.env.STATIC_DIR || 'static')

/* Arguments
 * object of hostnames mapped to folders (you need to create folders in static directory with the same names) - required
 * path to your static directory - required
 * path to default folder (in case if none of hostnames matched this one will be used) - not required
*/
app.use(vhost({
    "example.com": "example",
    "example2.com": "example2",
    "example3.com": "example3"
}, STATIC_DIR, 'default'))

module.exports = app.listen(80, () => {
  console.log(`Listening on http://localhost:80`)
})

Static directory structure

static
└── example1
    └── index.html
└── example2
    └── index.html
└── example3
    └── index.html
└── default
    └── index.html

koa2-vhost's People

Contributors

1m50rry avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.