Socket
Socket
Sign inDemoInstall

leajs-server

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

leajs-server

extendable, configuration based http server


Version published
Weekly downloads
36
decreased by-61.7%
Maintainers
1
Weekly downloads
 
Created
Source

Leajs

extendable, configuration based http server.

Features

  • Snapshots only - forces you to do proper tests of input -> output
  • Interactively shows you the output and asks about it
  • Uses webpack bundles to track changes
  • Watches test files and dependencies
  • Static analysis of tests to make writing them as easy as possible

Install

npm install --save leajs-server

Usage

# cli
usage: leajs <options> (config file)

options:
-w, --watch         restart server on changes in config
-p, --prod          sets NODE_ENV to "production"
    --port [port]   opens server on [port]

config file is optional and defaults to "leajs.config.[js|json|coffee|ts]"
in "server/" and "/"
// in node
Leajs = require("leajs-server")

// available options
// name (String) Default:"leajs.config" Name of the configuration file
// watch (Boolean) Starts the server in watch mode
// config (Object) Overwrites configuration file

Leajs(options)
.then((leajs) => {
  // finished
  leajs.close() // returns promise
})
.catch((e) => {
  // got some error
})

leajs.config

Read by read-conf, from ./ or ./server/ by default.

module.exports = {

  // namespace for the server e.g. /leajs
  base: "", // String

  // Disable some of the default plugins
  // $item (String) Package name or filepath (absolute or relative to cwd) of plugin
  disablePlugins: null, // Array

  // Default file to serve when in folder
  index: "index.html", // String

  // Listen object for httpServer
  // type: Object
  listen: {

    // Hostname for listening
    // Default: if inProduction then "localhost" else null
    host: null, // String

    // Port or socket to listen to
    // Default: if process.env.LISTEN_FDS then {fd: 3} else 8080
    port: null, // [Object, Number]

  },

  // Leajs plugins to load
  // type: Array
  // $item (String) Package name or filepath (absolute or relative to cwd) of plugin
  plugins: ["leajs-files","leajs-folders","leajs-encoding","leajs-cache","leajs-locale","leajs-eventsource","leajs-redirect"],

  // Custom respond function for quick debugging or testing
  respond: null, // [Function, Array]

  // Level of logging
  verbose: 1, // Number

  // …

}

Custom respond function

module.exports = {
  respond: (req) => {
    // req.request raw request object
    if (req.url == "/hello"){
      req.body = "hello world!"
    }
  }
}

Plugins

You should read the (short) docs of the bold ones.

Activated by default:

Installed and activated manually

License

Copyright (c) 2018 Paul Pflugradt Licensed under the MIT license.

FAQs

Package last updated on 29 May 2018

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc