All Projects → joakimunge → denoliver

joakimunge / denoliver

Licence: MIT license
A simple, dependency free static file server for Deno with possibly the worst name ever.

Programming Languages

typescript
32286 projects
Makefile
30231 projects

Projects that are alternatives of or similar to denoliver

dataStructure
Implement different Data Structures using TypeScript and JavaScript. Deno Third-party Module.
Stars: ✭ 24 (-74.47%)
Mutual labels:  deno, denoland
deno-mongo-api
Example for building REST APIS with deno and MongoDB
Stars: ✭ 17 (-81.91%)
Mutual labels:  deno, denoland
Fae
A functional module for Deno inspired from Ramda.
Stars: ✭ 44 (-53.19%)
Mutual labels:  deno, denoland
cnpj
🇧🇷 Format, validate and generate CNPJ numbers in Node & Deno
Stars: ✭ 26 (-72.34%)
Mutual labels:  deno, denoland
deno-x-ranking
🦕 Deno Third Party Modules Ranking 👑
Stars: ✭ 28 (-70.21%)
Mutual labels:  deno, denoland
logrocket deno api
A functional CRUD-like API with Deno and Postgres
Stars: ✭ 23 (-75.53%)
Mutual labels:  deno, denoland
kafkaSaur
Apache Kafka client for Deno
Stars: ✭ 42 (-55.32%)
Mutual labels:  deno, denoland
ssvm-deno-starter
A template project to run Rust functions in Deno through the Second State WebAssembly engine.
Stars: ✭ 50 (-46.81%)
Mutual labels:  deno, denoland
make-deno-edition
Automatically makes package.json projects (such as npm packages and node.js modules) compatible with Deno.
Stars: ✭ 39 (-58.51%)
Mutual labels:  deno, denoland
LiveReloadServer
A self-contained, local, cross-platform, static file Web Server with automatic Live Reloading, Markdown rendering and loose Razor Pages support.
Stars: ✭ 69 (-26.6%)
Mutual labels:  web-server, live-reload
Sanic
Async Python 3.7+ web server/framework | Build fast. Run fast.
Stars: ✭ 15,660 (+16559.57%)
Mutual labels:  web-server
Servr
A simple HTTP server in R
Stars: ✭ 228 (+142.55%)
Mutual labels:  web-server
smurf
simple markdown surfer
Stars: ✭ 38 (-59.57%)
Mutual labels:  web-server
media types
Deprecated. Use std/media_types instead.
Stars: ✭ 21 (-77.66%)
Mutual labels:  deno
Awot
Arduino web server library.
Stars: ✭ 200 (+112.77%)
Mutual labels:  web-server
dmm
Lightweight Deno Module Manager
Stars: ✭ 59 (-37.23%)
Mutual labels:  deno
Python Socketio
Python Socket.IO server and client
Stars: ✭ 2,655 (+2724.47%)
Mutual labels:  web-server
Mojo
✨ Mojolicious - Perl real-time web framework
Stars: ✭ 2,298 (+2344.68%)
Mutual labels:  web-server
Catacumba
Asynchronous web toolkit for clojure built on top of Ratpack / Netty
Stars: ✭ 192 (+104.26%)
Mutual labels:  web-server
discord-emoji
[Library/Deno] A near exact emoji tables of Discord for string-based insertion of emotes without having to escape Unicode.
Stars: ✭ 37 (-60.64%)
Mutual labels:  deno

It's a liver


Denoliver is a small, zero config dev & static file server with live reloading written in TypeScript for Deno intended for prototyping and Single Page Applications.

Prerequisites

To run this you need to have Deno 1.0 or later installed.

Key Features

  • Dependency free! No third party dependencies.
  • Live reload
  • Supports client side routing for Single Page Applications.
  • Directory lists
  • Supports HTTPS
  • Allows for programmatic use as a module
  • Boilerplating for rapid prototyping.
  • Injectable HTTP request interceptors. (TS & JS)

Getting started

Install as a Deno executable.

NOTE: Deno is a secure runtime by default. You need to include the --allow-net, --allow-read and --allow-write flags to make sure Denoliver can serve your directory.

$ deno install --allow-net --allow-read --allow-write --allow-run https://deno.land/x/denoliver/mod.ts

or if you're not happy with the name:

$ deno install -n whateverNameYouWant --allow-net --allow-read --allow-write --allow-run https://deno.land/x/denoliver/mod.ts

Why do I need the --allow-run flag?

You don't need it! You can still use Denoliver as normal without this flag.

Currently Deno does not provide a way to access local network interfaces, so to do this you need to allow denoliver to spawn the subprocess ipconfig and fetch the address from there. When this implementation gets finished, this module will probably be deprecated.

This code is published for you to use here: https://github.com/joakimunge/deno-local-ip/

Running

Serve your directory

$ denoliver ./demo

Options

Denoliver comes with a couple of options to customize your experience.

-h                 # Help
-n                 # Disable live reload - Defaults to false
-s                 # Disable all output - Defaults to false
-p <PORT>          # Specify desired port - Defaults to 8080
-d                 # Debug for more verbose output - Defaults to false
-t                 # Use HTTPS - Requires a trusted self-signed certificate
-l                 # Use directory listings - Disables routing (SPA)
-c                 # Use CORS - Defaults to false
--before=<..>   # Before request Interceptor(s)
--after=<..>    # After request Interceptor(s)
--certFile=<..>    # Specify certificate file - Defaults to denoliver.crt
--keyFile=<..>     # Specify key file - Defaults to denoliver.key
--entry=<..>       # Specify optional entrypoint - Defaults to index.html

Directory Listing

Denoliver supports indexing of served directories and provides a simple interface, with dark mode support, for navigating a project folder.

Directory listing

Optional boilerplating

If the given directory doesn't exist, denoliver will ask you if you want to create a boilerplate. This will generate an a basic project folder and serve it for you. Very useful to get up and running quickly.

├── index.html
├── index.css
├── app.js

Interceptors

Denoliver allows you to inject your own request interceptors to be fired before or after the HTTP requests has been handled by the server. This can be one or more functions which have access to the request object (instance of Deno.Request) and gets called in the order they are defined with the output of the previous function (piped). These functions must all return the request object.

Interceptors can be a single function, for example:

// before.ts

export default (req: ServerRequest) => {
  req.headers.set('Authorization', 'Bearer some-token')
  return req
}

or an array of functions:

const setHeaders = (req: ServerRequest) => {
  req.headers.set('Authorization', 'Bearer some-token')
  return req
}

const logRequestUrl = (req: ServerRequest) => {
  console.log(req.url)
  return req
}

export default [setHeaders, logRequestUrl]

of course this can also be used when using Denoliver as a module:

const server = denoliver({
  port: 6060,
  before: (req: ServerRequest) => {
    req.headers.set('Authorization', 'Bearer some-token')
    return req
  },
})

Configuration

If you want, you can place a configuration file called denoliver.json in the folder you are serving to avoid having to use command line arguments to customize its behaviour. By default it will look like this:

{
  "root": ".",
  "port": 8080,
  "disableReload": false,
  "silent": false,
  "debug": false,
  "secure": false,
  "cors": false,
  "list": false,
  "before": "before.ts",
  "after": "after.ts",
  "certFile": "some_file.crt",
  "keyFile": "some_file.key",
  "entryPoint": "index.html"
}

API

Denoliver can also be used as a module in any Deno project. This exposes an instance of Deno.Server.

The main function accepts the same config object as specified in the config file above.

import denoliver from 'https://deno.land/x/denoliver/mod.ts'

const server = denoliver({ port: 6060, cors: true })

server.close() // Close the server

Serve over HTTPS

To use HTTPS you will need a trusted self-signed certificate. If you're on macOS you can use This bash script to easily generate one.

Name the cert and key files denoliver.crt and denoliver.key and place them in your working dir. You can configure these names to be whatever you want with the config file, or the --certFile and --keyFile flags.

Disclaimer

This project is not intended for production use. It started out as a way for me personally to learn Deno, and is merely a tool to quickly get a file server up and running.

Acknowledgements

This project was heavily inspired by lukejacksonns fantastic Servor

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].