webpack-symmetric
v1.0.13
Published
Webpack dev server configurations for running a proxy to a backend including self-signed certs.
Downloads
4
Readme
About
This package exposes a single function createBackendProxy({...})
which will generate a proxy configuration and self-signed certs.
Usage
The generated proxy configuration will do the following things:
- Create request/response handlers that route to the backend any path starting with anything from
options.paths
or any second-level path fromoptions.subpaths
. - Reset
sessionid
cookies when switching between projects. - Generate a self-signed root cert and add it as trusted to your keychain. So no browser warnings should ever popup.
- Generate a root signed cert used in the proxy, which includes standard alternate names of
localhost
,<host>.local
,127.0.0.1
, any other detected interface ips, and your externally facing ip.
NOTE: SSL cert generation only happens when webpack
is run as webpack-dev-server
The root CA cert
In order to avoid warnings in your browser make sure that the root CA cert is installed as a trusted root cert in your system after the first time running webpack server. This only needs to be done once and not repeated for every project. On OSX this is done automatically but look for a console message on other systems.
Installing the root CA cert on other devices
See certServer
setting below and follow the instructions on the installation page.
createBackendProxy
options
The only required option is backend
, everything else is optional.
backend
- The backend origin to proxy topaths
- The first-level URL paths to match and proxy to the backendsubpaths
- The second-level URL paths to match and proxy to the backendoriginRewrites
- Array of origins to localize as relative paths instead when found under src or href attributes in a proxied responseinsecure
- If true run the server as http instead of self-signed httpsgenerateCert
- If true will force the certificate to be generated outside of awebpack-dev-server
invocationscertServer
- If true will run a separate http server on port 3007 with instructions on installing the root cert on other devicesssl.additionalDomains
- Additional domain names to add as alternate names allowed with the SSL certssl.additionalIPs
- Additional IP addresses to add as alternate names allowed with the SSL certssl.home
- Root directory used to store all generated certs and keys. Defaults to~/.symmetric
Environment variables
CERT_SERVER=true
- Can be used instead of thecertServer
optionGENERATE_CERT=true
- Can be used in place of thegenerateCert
optionSYMMETRIC_HOME
- Can be used instead of thessl.home
option
Setting up devServer in webpack
Add the following settings to your webpack devServer configuration object to get the proxy going.
First generate a proxy
configuration using proxy = createBackendProxy({...})
. Within your devServer
object:
- Set
proxy: { '/': proxy }
for the most basic setup off the root URL path - If running with SSL, set
https: proxy.ssl
- Optionally, set
host: '0.0.0.0'
to allow any remote connection in not just from localhost, needed if running inside a VM - Optionally, to allow connections to mDBS
.local
hostnames, setallowedHosts: ['localhost', '.local']
License
MIT