All Projects → lukejacksonn → Servor

lukejacksonn / Servor

Licence: mit
Dependency free file server for single page app development

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Servor

Local Web Server
A lean, modular web server for rapid full-stack development.
Stars: ✭ 916 (+36.31%)
Mutual labels:  server, single-page-app
Papercut Smtp
Papercut SMTP -- The Simple Desktop Email Server
Stars: ✭ 2,094 (+211.61%)
Mutual labels:  server, development
Webpack Serve
Repository has moved:
Stars: ✭ 1,125 (+67.41%)
Mutual labels:  server, development
Mailcatcher
Catches mail and serves it through a dream.
Stars: ✭ 5,512 (+720.24%)
Mutual labels:  server, development
Foxman
🍥 an extensible mock server
Stars: ✭ 76 (-88.69%)
Mutual labels:  server, development
Electron Serve
Static file serving for Electron apps
Stars: ✭ 310 (-53.87%)
Mutual labels:  server, single-page-app
Laravel Server Monitor
Don't let your servers just melt down
Stars: ✭ 595 (-11.46%)
Mutual labels:  server
Vue Crud
Vue.js based REST-ful CRUD system
Stars: ✭ 629 (-6.4%)
Mutual labels:  single-page-app
Swiftserverside Vapor
🦄 Swift server open source projects based on the Swift 4.1 and Vapor 3 frameworks. (Swift 服务端开源项目)
Stars: ✭ 588 (-12.5%)
Mutual labels:  server
Ram
⚛️ React Application Manager: create and run React (and other) applications – no command line or build setup required
Stars: ✭ 585 (-12.95%)
Mutual labels:  development
Gameproject3
游戏服务器框架,网络层分别用SocketAPI、Boost Asio、Libuv三种方式实现, 框架内使用共享内存,无锁队列,对象池,内存池来提高服务器性能。还包含一个不断完善的Unity 3D客户端,客户端含大量完整资源,坐骑,宠物,伙伴,装备, 这些均己实现上阵和穿戴, 并可进入副本战斗,多人玩法也己实现, 持续开发中。
Stars: ✭ 655 (-2.53%)
Mutual labels:  server
Stathub Go
A smart Hub for holding server stat
Stars: ✭ 650 (-3.27%)
Mutual labels:  server
Spock
Another Haskell web framework for rapid development
Stars: ✭ 623 (-7.29%)
Mutual labels:  server
Pilbox
An image resize application server
Stars: ✭ 597 (-11.16%)
Mutual labels:  server
Micro Dev
The development environment for `micro`
Stars: ✭ 630 (-6.25%)
Mutual labels:  development
Reflection
DEPRECATED
Stars: ✭ 592 (-11.9%)
Mutual labels:  server
Coiniumserv
Next-gen crypto currency mining pool software
Stars: ✭ 651 (-3.12%)
Mutual labels:  server
Milo
Eclipse Milo™ - an open source implementation of OPC UA (IEC 62541).
Stars: ✭ 587 (-12.65%)
Mutual labels:  server
Rouille
Web framework in Rust
Stars: ✭ 617 (-8.18%)
Mutual labels:  server
Invoice printer
Super simple PDF invoicing
Stars: ✭ 644 (-4.17%)
Mutual labels:  server

Servør

A dependency free dev server for modern web application development

A very compact but capable static file server with https, live reloading, gzip and other useful features to support modern web app development on localhost and over a local network. The motivation here was to write a package from the ground up with no dependencies; using only native, node and browser APIs to do some specific tasks with minimal code.

Servør can be invoked via the command line or programmatically using the node API.

Quickstart Example

The following command instructs servør to; clone perflink, start a server at the project root, open the url in a browser, open the source code in an editor and reload the browser when files change.

npx servor gh:lukejacksonn/perflink --browse --editor --reload

Most features are disabled by default but you can customize behaviour by passing positional arguments and flags to enable features.


servor

Features

  • 🗂 Serves static content like scripts, styles, images from a given directory
  • ♻️ Reloads the browser when project files get added, removed or modified
  • 🗜 Uses gzip on common filetypes like html, css, js and json
  • 🔐 Supports https and http2 with trusted self signed certificates
  • 🖥 Redirects all path requests to a single file for frontend routing
  • 📦 Accepts both HTML and JavaScript files as the root file for a directory
  • 🔎 Discovers freely available ports to start if the default is in use
  • 📄 Renders directory listing for urls ending with a trailing slash
  • 🗃 Opens browser tab and code editor to streamline quick start

CLI Usage

Run as a terminal command without adding it as a dependency using npx:

npx servor <root> <fallback> <port>

You can pass a GitHub repo as <root> using the syntax gh:<user>/<repository>

  • <root> path to serve static files from (defaults to current directory .)
  • <fallback> the file served for all non-file requests (defaults to index.html)
  • <port> what port you want to serve the files from (defaults to 8080)

Optional flags passed as non-positional arguments:

  • --browse causes the browser to open when the server starts
  • --reload causes the browser to reload when files change
  • --secure starts the server with https using generated credentials
  • --silent prevents the server node process from logging to stdout
  • --module causes the server to wrap the root in script type module tags
  • --static causes the server to route nested index files if they exist
  • --editor opens a code editor (currently only vscode) at the project root

Example usage with npm scripts in a package.json file after running npm i servor -D:

{
  "devDependencies": {
    "servor": "4.0.0"
  },
  "scripts": {
    "start": "servor www index.html 8080 --reload --browse"
  }
}

Generating Credentials

NOTE: This process depends on the openssl command existing (tested on macOS and linux only)

The files servor.crt and servor.key need to exist for the server to start using https. If the files do not exist when the --secure flag is passed, then certify.sh is invoked which:

  • Creates a local certificate authority used to generate self signed SSL certificates
  • Runs the appropriate openssl commands to produce:
    • a root certificate (pem) so the system will trust the self signed certificate
    • a public certificate (crt) that the server sends to clients
    • a private key for the certificate (key) to encrypt and decrypt traffic

Adding credentials to the trusted store

NOTE: This process depends on the sudo and security commands existing (tested on macOS only)

For the browser to trust self signed certificates the root certificate must be added to the system trusted store. This can be done automatically by running sudo servor --secure which:

  • Adds the root certificate to the system Keychain Access
  • Prevents the "⚠️ Your connection is not private" screen
  • Makes the 🔒 icon appear in the browsers address bar

The approach was adopted from @kingkool68/generate-ssl-certs-for-local-development

API Usage

Use servor programmatically with node by requiring it as a module in your script:

const servor = require('servor');
const instance = await servor({
  root: '.',
  fallback: 'index.html',
  module: false,
  static: false,
  reload: false,
  inject: ''
  credentials: null,
  port: 8080,
});

The servor function accepts a config object with optional props assigned the above default values if none are provided. Calling the servor function starts up a new server and returns an object describing its configuration.

const { url, root, protocol, port, ips } = await servor(config);

Inject

The inject property accepts a string that gets appended to the servers root document (which is index.html by default). This could be used to inject config or extend the development servers behavior and capabilities to suit specific environments.

const config = require('package.json');
servor({ inject: `<script>window.pkg=${config}</script>` });

Credentials

The credentials property accepts an object containing the entries cert and key which must both be valid for the server to start successfully. If valid credentials are provided then the server will start serving over https.

It is possible to generate the appropriate credentials using the --secure CLI flag.

Notes

Thanks to all the contributors to this projects so far. If you find a bug please create an issue or if you have an idea for a new feature then fork the project and create a pull request. Let me know how you are using servør on twitter.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].