cdnproxy

package module
v0.0.0-...-3f41a2a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2020 License: MIT Imports: 8 Imported by: 0

README

echo-cdn-proxy

Build Status

Summary

An echo middleware to proxy and cache js requests to a specified CDN

Usage

package main

import (
    "net/http"
    "time"

    "github.com/eiri/echo-cdn-proxy"
    "github.com/labstack/echo/v4"
    "github.com/labstack/echo/v4/middleware"
)

func main() {
    e := echo.New()

    // Configure the middleware
    cfg := cdnproxy.NewConfig("https://cdn.jsdelivr.net", "/npm")
    e.Use(cfg.Proxy)

    // Start the server
    e.Logger.Fatal(e.Start(":8000"))
}
$ curl http://localhost:8000/npm/vue/dist/vue.min.js
...

Dev

$ git clone https://github.com/eiri/echo-cdn-proxy
$ cd echo-cdn-proxy
$ make test
go build ./...
go test -v ./...
=== RUN   TestProxy
=== RUN   TestProxy/echo_router_simple
=== RUN   TestProxy/echo_router_with_static
=== RUN   TestProxy/echo_router_with_prefix_clash
--- PASS: TestProxy (0.00s)
    --- PASS: TestProxy/echo_router_simple (0.00s)
    --- PASS: TestProxy/echo_router_with_static (0.00s)
    --- PASS: TestProxy/echo_router_with_prefix_clash (0.00s)
=== RUN   TestProxyNotFound
--- PASS: TestProxyNotFound (0.00s)
PASS
ok      github.com/eiri/echo-cdn-proxy  0.274s

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	CDN    *url.URL
	Prefix string
	Client *http.Client
	Cache  *cache.Cache
}

Config keeps proxy configuration

func NewConfig

func NewConfig(baseURL, prefix string) Config

NewConfig returns new proxy configured with given CDN and prefix

func (Config) Proxy

func (cfg Config) Proxy(next echo.HandlerFunc) echo.HandlerFunc

Proxy is the middleware echo handler

type Entry

type Entry struct {
	CType string
	Data  []byte
}

Entry is a Cache entry for CDN file

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL