Giter VIP home page Giter VIP logo

easy-https's Introduction

easy-https

Zero config, one step local https server with custom local domain.

What it does?

  • Will automatically add proper domain entries to /etc/hosts
  • Will ask you for admin password only if needed on first run / domain change
  • Will prepare https certificates for given domains
  • Will trust those certificates on your local machine
  • Will open the browser on start pointing to your local server https url

Demo

Demo

Usage with plain node:

import { createHttpsDevServer } from 'easy-https';

async function start() {
  const server = await createHttpsDevServer(
    async (req, res) => {
      res.statusCode = 200;
      res.write('ok');
      res.end();
    },
    {
      domain: 'my-app.dev',
      port: 3000,
      subdomains: ['test'], // will add support for test.my-app.dev
      openBrowser: true,
    },
  );
}

start();

Usage with Express

import { createHttpsDevServer } from 'easy-https';
import express from 'express';
const app = express();

createHttpsDevServer(app, config);

Usage with Next.js

import { createHttpsDevServer } from 'easy-https';
import next from 'next';
import { parse } from 'url';

const app = next({ dev: IS_DEV });
const requestHandler = app.getRequestHandler();

async function start() {
  await app.prepare();

  const { server, url } = await createDevServer((req, res) => {
    const parsedUrl = parse(req.url!, true);
    requestHandler(req, res, parsedUrl);
  }, config);

  logger.log(`Server ready. ๐Ÿš€`);
}

start();

API usage, avaliable options

interface ServerConfig {
  // Main Local domain
  domain: string;
  // Local port to listen on
  port: number;
  // List of subdomains
  subdomains?: string[];
  // If should open web browser when server is ready
  openBrowser?: boolean;
  // Custom logger - defaults to console.info
  logger?: (...args: any) => void;
}

function createHttpsDevServer(
  // Normal node.js (req, res) handler.
  handler: RequestListener,
  config: ServerConfig,
): Promise<{
  // https local server url.
  url: string;
  // Node https server instance
  server: Server;
}>;

Notes

NEVER USE IN PRODUCTION

This lib is intended to make it easy to setup local https server with custom local domain. It is not meant to be secure in any way.

It is not tested on Windows. If you want, feel free to send proper PR adding Windows support.

Licence

Mit.

easy-https's People

Contributors

pie6k avatar unibreakfast avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

easy-https's Issues

Windows support ?

As you have suggested in Reddit, I think it would be good to have Windows support. For educational purpose.

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.