abhishektiwari / nuxt-custom-domain-with-tls

Example implementation of custom domains support with on-demand TLS (HTTPS) using Nuxt and Caddy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom Domains with On-demand TLS

Example implementation of custom domains support with on-demand TLS (HTTPS) using Nuxt and Caddy.

  • Caddy to provision on-demand TLS on wildcard domain/custom domain
  • Nuxt middleware to detect domain forwarded by Caddy as host header

Architecture

High-level

High-level Architecture

Application Level

Nuxt Domain Middleware

Running

Clone this repository and follow instructions below.

Nuxt build setup

a. Install dependencies

yarn install

b. Serve with hot reload at localhost:3000

yarn dev

c. Build for production and launch server,

yarn build
yarn start

d. Generate static project

yarn generate

For detailed explanation on how things work, check out Nuxt.js docs.

Run locally with wildcard domains

First lets get DNS foo.bar/go.compare mapped to localhost,

a. Install dnsmasq

brew install dnsmasq

b. Start dnsmasq service

sudo brew services start dnsmasq

c. Add following to the bottom of the /usr/local/etc/dnsmasq.conf

conf-dir=/usr/local/etc/dnsmasq.d,*.conf

d. Create our first config file

mkdir -p /usr/local/etc/dnsmasq.d
touch /usr/local/etc/dnsmasq.d/development.conf
nano /usr/local/etc/dnsmasq.d/development.conf

e. Add following in development.conf

address=/foo.bar/127.0.0.1
address=/go.compare/127.0.0.1

f. In /etc/resolver add new files foo.bar/go.compare with following content,

nameserver 127.0.0.1

g. Restart dnsmasq and check DNS

sudo brew services restart dnsmasq
scutil --dns

Local Caddy setup

a. Install Redis for storage,

brew install redis

b. Install XCaddy,

cd server
export GO111MODULE=on
go get github.com/caddyserver/xcaddy/cmd/xcaddy@latest
xcaddy build v2.3.0 --with github.com/gamalan/caddy-tlsredis

c. Run Caddy Server

cd server
./caddy run --config CaddyfileLocal

About

Example implementation of custom domains support with on-demand TLS (HTTPS) using Nuxt and Caddy

License:MIT License


Languages

Language:JavaScript 55.9%Language:Vue 44.1%