npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-https-provider

v1.0.12

Published

<a href="https://www.npmjs.com/package/express-https-provider"><img src="https://img.shields.io/npm/dw/express-https-provider.svg" alt="Downloads"></a> <a href="https://github.com/seafoodframework/express-https-provider"><img src="https://img.shields.io/n

Downloads

4

Readme

express-https-provider

Description

This is a JavaScript library that helps you to run development express server with trusted ssl certificate easily or get a valid certificate to run a dev server using different from express library. Forget about chrome warnings, errors and etc. Please, never use this library on production server.

Attention! Your server will be serving both at https://yourapp.name and http://localhost, but all request will be redirected to the first one by default.

Browser screenshot of trusted certificate on local machine (node.js)

Installation

You can use yarn or npm to install this package.

Yarn

yarn add --dev express-https-provider

npm

npm install --save-dev express-https-provider

Usage

const provider = require('express-https-provider')()

provider
  .modifyApp((app, state) => {
    app.get('/', (request, response) => {
      response.send('example')
    })
  })
  .done((http, https, state) => {
    console.log(`Serving at ${state.getServingLink()}`)
  })
  .run()

Documention

Methods

Note that modifyApp, modifyRedirect, done, disableRedirectToHttps and addCloseEventHandler return link to the object on which you call the method so you can combine it in chain.

const provider = require('express-https-provider')()

provider
    .disableRedirectToHttps()
    .modifyApp(app => {
      //
    })
    .modifyRedirect(redirect => {
      //
    })

modifyApp

Allow to set up your express server before it runs.

Arguments
  • app - This is an express server instance that process client requests. Use this object to set up your server.
  • state - AppState instance
const provider = require('express-https-provider')()

provider
    .modifyApp((app, state) => {
      app.get('/', (request, response) => {
        response.send(`Serving at ${state.getServingLink()}`)
      })
    })

modifyRedirect

Allow to set up custom logic on each request before it runs.

Arguments
  • redirect - This is an express server instance used to redirect each request to 'app' express instance.
  • state - AppState instance
const provider = require('express-https-provider')()

provider
    .modifyRedirect((redirect, state) => {
      redirect.all('*', (request, response, next) => {
        if (request.secure) {
          return next()
        }
        // do something
      })
    })

done

It is an event hook fired after server running.

Arguments
const provider = require('express-https-provider')()

provider
  .done((http, https, state) => {
    console.log(`Serving at ${state.getServingLink()}`)
    
    // As example
    http.close()
  })
  .run()

disableRedirectToHttps

Use this method if you don't want to auto redirect from http://localhost to https://yourapp.name.

No arguments
const provider = require('express-https-provider')()

provider
  .disableRedirectToHttps()
  .run()

addCloseEventHandler

It is an event hood fired before server stopping.

Arguments
const provider = require('express-https-provider')()

provider
  .addCloseEventHandler(state => {
    console.log(`Stop serving at ${state.getServingLink()}`)
  })
  .run()

run

This method runs express server.

If you don't want to run express server and just want to get a certificate to use it on your own you can use certificate method.

No arguments

Return promise

const provider = require('express-https-provider')()

provider.run()

You can await this method if you need to do it sync.

const provider = require('express-https-provider')()

const runProvider = async () => {
  await provider.run()
  // Server was run but done hook may not be fired yet!
}

certificate

Provide trusted SSL certificate without server running.

Attention! Chainable method like modifyApp and others actions do NOT make any effect on it.

No arguments

Return promise

const provider = require('express-https-provider')()

provider.certificate()
    .then(certificate => {
      const {cert, key} = certificate
      // do whatever you need
    })
    .catch(error => {
      console.error('Whoops, something went wrong :(')
    })

AppState

Methods

getServingLink
No arguments

Return string

The method returns secure URL your server serving at. If 443 port is free it returns https://yourapp.name, otherwise it do https://yourapp.name:${port} where ${port} is automatically selected free port. If you need to get a port number for secure URL you can use getHttpsPort method.

getNotSecureServingLink

Return string

The method returns not secure URL your server serving at. If 80 port is free it returns http://localhost, otherwise it do http://localhost:${port} where ${port} is automatically selected free port. If you need to get a port number for not secure URL you can use getHttpPort method.

getHttpPort
No arguments

Return int

The method returns port your http server listening on. If 80 port was free it return 80, otherwise automatically selected free port.

getHttpsPort
No arguments

Return int

The method returns port your https server listening on. If 443 port was free it return 443, otherwise automatically selected free port.

getHostname
No arguments

Return string

The method returns virtual host domain name your https server serving at. Currently is yourapp.name.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT