Skip to content

Commit

Permalink
Release 0.1.0 (#14)
Browse files Browse the repository at this point in the history
* Update dependencies

* Custom config mapping (#13)

* Created config mapping draft

* Reafactoring

* Simplify

* Use new url mapping in applocation

* Fixed method name

* Updated readme

* Reafactoring

* Move all structures to configuration

* Static file serving (#15)

* Created configuration structure

* Covered decoding by tests

* Fixed configuration decoding issues

* Created static directory mapping

* Fixed cloning issue

* Added tests for static serving

* Added static dirs pringing

* Changed handler structure

* Added static middleware draft

* Fixed index file serving

* Added base tests for static middleware

* Fixed mapping tests

* Fixed middelware tesrs

* Added tests fro normalise helper

* Added tests for uncors handler

* Added tests for index file

* Added tests for mocks

* Enabled skipped tests

* Added fir for prefix cutting

* Fixed error handling

* Added tests for mocks handler registration

* Fixed sonar issues

* Updated readme

* Update README.md

* Added new error page

* Update roadmap

* Rename configuration module to config

* Rename infrastructure module to infra

* Updated Roadmap

* Updated README.md

* Separated mock for each url mapping (#16)

* Created draft

* Fixed tests

* Reorganised structure

* Fixed lint issues

* Updated mapping formatting

* Fixed tests

* Added CloneMap helper

* Move NormaliseMappings to config package

* Added tests for config models

* Cleanup code

* Cleanup code

* Changed correct errors message ordering

* Added helpers.CloseSafe method

* Fixed mock waiting issue

* Updated packages

* Refactor debug output for logger

* Refactored code

* Added tests for sfmt package

* Added short commands

* Renamed config property raw-content to raw

* Cleared test output

* Cleanup code: WIP 1

* Cleanup code: WIP 2

* Cleanup code: WIP 3

* Cleanup code: WIP 4

* Updated README.md

* Cleanup code: WIP 4
  • Loading branch information
Evgeny Abramovich committed Jun 3, 2023
1 parent 8c15020 commit 3826025
Show file tree
Hide file tree
Showing 122 changed files with 4,500 additions and 2,077 deletions.
12 changes: 5 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
run:
skip-dirs:
- testing
- dist
linters:
enable-all: true
disable:
Expand All @@ -26,16 +22,18 @@ linters:
- exhaustruct
- wsl
- gci
- gofmt
- gofumpt
- nolintlint
- tagliatelle
- maintidx
- ireturn
- bodyclose
linters-settings:
varnamelen:
ignore-names:
- form
- to
- ok
- fs
- ca
presets:
- bugs
- comment
Expand Down
2 changes: 2 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json

project_name: uncors
before:
hooks:
Expand Down
192 changes: 38 additions & 154 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
</a>
</p>
<p align="center">
A simple dev HTTP/HTTPS proxy for replacing CORS headers.
A simple dev HTTP/HTTPS proxy for replacing CORS headers.
</p>
<p align="center">
<a href="https://go.dev">
<img alt="Go version" src="https://img.shields.io/github/go-mod/go-version/evg4b/uncors">
</a>
<a href="https://github.com/evg4b/uncors/releases/latest">
<img alt="GitHub version" src="https://img.shields.io/github/v/tag/evg4b/uncors?label=version">
</a>
<a href="https://go.dev">
<img alt="Go version" src="https://img.shields.io/github/go-mod/go-version/evg4b/uncors">
</a>
<a href="https://github.com/evg4b/uncors/releases/latest">
<img alt="GitHub version" src="https://img.shields.io/github/v/tag/evg4b/uncors?label=version">
</a>
<a href="https://github.com/evg4b/uncors/blob/main/LICENSE">
<img alt="License" src="https://img.shields.io/github/license/evg4b/uncors?label=license">
</a>
<a href="https://sonarcloud.io/summary/new_code?id=evg4b_uncors">
<img alt="Coverage" src="https://sonarcloud.io/api/project_badges/measure?project=evg4b_uncors&metric=coverage">
<a href="https://sonarcloud.io/summary/new_code?id=evg4b_uncors&branch=develop">
<img alt="Coverage" src="https://sonarcloud.io/api/project_badges/measure?project=evg4b_uncors&metric=coverage&branch=develop">
</a>
<a href="https://goreportcard.com/report/github.com/evg4b/uncors">
<img alt="Go Report Card" src="https://goreportcard.com/badge/github.com/evg4b/uncors">
Expand All @@ -37,14 +37,16 @@
# Core features

- CORS header replacement
- HTTPS support
- Wildcard URL request mapping
- Simple request/response mocking
- HTTP/HTTPS proxy support
- *Static file serving ([coming soon...](./ROADMAP.md))*
- [Wildcard host mapping](https://github.com/evg4b/uncors/wiki/2.-Configuration#wilcard-mapping)
- [HTTPS support](https://github.com/evg4b/uncors/wiki/2.-Configuration#https-configuration)
- [Response mocking](https://github.com/evg4b/uncors/wiki/3.-Response-mocksing)
- [HTTP/HTTPS proxy support](https://github.com/evg4b/uncors/wiki/2.-Configuration#proxy-configuration)
- [Static file serving](https://github.com/evg4b/uncors/wiki/4.-Static-file-serving)
- *Response caching ([coming soon...](./ROADMAP.md))*

Other new features you can find in [UNCORS roadmap](https://github.com/evg4b/uncors/blob/main/ROADMAP.md)
Other new features you can find in [roadmap](https://github.com/evg4b/uncors/blob/main/ROADMAP.md).

Full documentation you can found on [wiki pages](https://github.com/evg4b/uncors/wiki).

# Quick Install

Expand Down Expand Up @@ -82,6 +84,22 @@ Via yarn:
yarn add uncors --dev
```

## Docker

We currently offer images for [Docker](https://hub.docker.com/r/evg4b/uncors)

```bash
docker run -p 80:3000 evg4b/uncors --from 'http://local.github.com' --to 'https://github.com'
```

## Stew (Cross-platform)

Also, you can install binaris using [Stew](https://github.com/marwanhawari/) with the following commands:

```bash
stew install evg4b/uncors
```

## Binary (Cross-platform)

Download the appropriate version for your platform
Expand All @@ -91,14 +109,6 @@ This works well for shared hosts and other systems where you don’t have a priv

Ideally, you should install it somewhere in your `PATH` for easy use. `/usr/local/bin` is the most probable location.

## Docker

We currently offer images for [Docker](https://hub.docker.com/r/evg4b/uncors)

```bash
docker run -p 80:3000 evg4b/uncors --from 'http://local.github.com' --to 'https://github.com'
```

## Build from source

**Prerequisite Tools**
Expand All @@ -123,140 +133,14 @@ If you are a Windows user, substitute the $HOME environment variable above with

# Usage

The following command can be used to start the Uncors proxy server:
The following command can be used to start the UNCORS proxy server:

```
uncors --http-port 8080 --to 'https://github.com' --from 'http://localhost'
uncors --from 'http://localhost' --to 'https://github.com' --http-port 8080
```

## CLI Parameters

The following command-line parameters can be used to configure the Uncors proxy server:

* `--from` - Specifies the local host with protocol for the resource from which proxying will take place.
* `--to` - Specifies the target host with protocol for the resource to be proxied.
* `--http-port` or `-p` - Specifies the local HTTP listening port.
* `--https-port` or `-s` - Specifies the local HTTPS listening port.
* `--cert-file` - Specifies the path to the HTTPS certificate file.
* `--key-file` - Specifies the path to the matching certificate private key.
* `--proxy` - Specifies the HTTP/HTTPS proxy to provide requests to the real server (system default is used by default).
* `--config` - Specifies the path to the [configuration file](#configuration-file).
* `--debug` - Enables debug output.

Any configuration parameters passed via CLI (except for `--from` and `--to`) will override the corresponding
parameters specified in the configuration file. The `--from` and `--to` parameters will add an additional mapping
to the configuration.

## Configuration file

Uncors supports a YAML file configuration with the following options:

```yaml
# Base configuration
http-port: 8080 # Local HTTP listened port.
mappings:
http://localhost:3000: https://githib.com
debug: false # Show debug output.
proxy: localhost:8080

# HTTPS configuration
https-port: 8081 # Local HTTPS listened port.
cert-file: ~/server.crt # Path to HTTPS certificate file.
key-file: ~/server.key # Path to matching for certificate private key.

# Mock definitions are used to generate fake responses for certain endpoints.
mocks:
- path: /hello-word
response:
code: 200
raw-content: 'Hello word'
```
More information about configuration and usage you can fiund on [UNCORS wiki](https://github.com/evg4b/uncors/wiki).

#### Mocks configuration

The mocks configuration section in Uncors allows you to define specific endpoints to be mocked, including the response
data and other parameters. Currently, mocks are defined globally for all mappings. Available path, method, queries, and headers filters,
which utilize the [gorilla/mux route matching system](https://github.com/gorilla/mux#matching-routes).

Each endpoint mock requires a path parameter, which defines the URL path for the endpoint. You can also use the method
parameter to define a specific HTTP method for the endpoint.

The queries and headers parameters can be used to specify more detailed URLs that will be mocked. The queries parameter
allows you to define specific query parameters for the URL, while the headers parameter allows you to define specific
HTTP headers.

Here is the structure of the mock configuration:

```yaml
mocks:
- path: <string>
method: <string>
queries:
<string>: <string>
# ...
headers:
<string>: <string>
# ...
response:
code: <int>
headers:
<string>: <string>
# ...
delay: <string>
raw-content: <string>
file: <string>
```
# ⚠️ Caution

- `path` (required) - This property is used to define the URL path that should be mocked. The value should be a string,
such as `/example`. The path can include variables, such as `/users/{id}`, which will match any URL that starts
with `/users/` and has a variable `id` in it.
- `method` (optional) - This property is used to define the HTTP method that should be mocked.
The value should be a string. If this property is not specified, the mock will match any HTTP method.
- `queries` (optional) - This property is used to define specific query parameters that should be matched against the
request URL. The value should be a mapping of query parameters and their values, such as `{"param1": "value1", "
param2": "value2"}`. If this property is not specified, the mock will match any query parameter.
- `headers` (optional): This property is used to define specific HTTP headers that should be matched against the request
headers. The value should be a mapping of header names and their values, such as `{"Content-Type": "application/json"}`.
If this property is not specified, the mock will match any HTTP header.
- `response` (required): This property is used to define the mock response. It should be a mapping that contains the
following properties:
- `code` (optional): This property is used to define the HTTP status code that should be returned in the mock
response. The value should be an integer, such as 200 or 404. If this property is not specified, the mock will use
200 OK status code.
- `headers` (optional): This property is used to define specific HTTP headers that should be returned in the mock
response. The value should be a mapping of header names and their values, such as `{"Content-Type": "
application/json"}`. If this property is not specified, the mock response will have no extra headers.
- `delay` (optional): This property is used to define a delay before sending the mock response. The value should be a
string in the format `<number><unit> <nunmber><units> ...`, where `<number>` is a positive integer and `<unit>` is time units.
Valid time units are `ns`, `us` (or `µs`), `ms`, `s`, `m`, `h`. For example, `1m 30s` would delay the response by 1 minute and 30
seconds. If this property is not specified, the mock response will be sent immediately.
- `raw-content` (optional): This property is used to define the raw content that should be returned in the mock
response. The value should be a string, such as `Hello, world!`. If this property is not specified, the mock
response will be empty.
- `file` (optional): This property is used to define the path to a file that contains the mock response content. The
file content will be used as the response content. The value should be a string that specifies the file path, such
as `~/mocks/example.json`. If this property is not specified, the mock response will be empty.

## How it works

```mermaid
sequenceDiagram
participant Client
participant Uncors
participant Server
alt Handling OPTIONS queries
Client ->> Uncors: Access-Control-Request
Uncors ->> Client: Allow-Control-Request
end
alt Handling Data queries
Client ->> Uncors: GET, POST, PUT... query
Note over Uncors: Replacing url with target<br/> in headers and cookies
Uncors-->>Server: Real GET, POST, PUT... query
Server->>Uncors: Real response
Note over Uncors: Replacing url with source<br/> in headers and cookies
Uncors-->>Client: Data response
end
```
Please note that removing or replacing CORS headers can pose potential security vulnerabilities. This tool is specifically designed to streamline the development and testing workflow and should not be used in a production environment or as a remote proxy server. It has not undergone a thorough security review, so caution should be exercised when utilizing it.
22 changes: 12 additions & 10 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

## [MVP (Pre-release)](https://github.com/evg4b/uncors/releases/tag/v0.0.0)

- [X] Base reverce proxy server functionality
- [X] Base reverse proxy server functionality
- [X] Url mapping

## [0.0.1 Release](https://github.com/evg4b/uncors/releases/tag/v0.0.1)

- [X] Cusrom port hadnling
- [X] New URL replcer functionality
- [X] Requset printing
- [X] Custom port handling
- [X] New URL replacer functionality
- [X] Request printing

## [0.0.2 Release](https://github.com/evg4b/uncors/releases/tag/v0.0.2)

Expand All @@ -25,20 +25,20 @@

## [0.0.4 Release](https://github.com/evg4b/uncors/releases/tag/v0.0.4)

- [X] Proxy from envairment support
- [X] Proxy from environment support
- [X] URL replacer v2 - [PR](https://github.com/evg4b/uncors/pull/2)

## [0.0.6 Release](https://github.com/evg4b/uncors/releases/tag/v0.0.6)

- [X] Added [scoop bucket](https://github.com/evg4b/scoop-bucket) support
- [X] Responce mocking v1 - [PR](https://github.com/evg4b/uncors/pull/3)
- [X] Response mocking v1 - [PR](https://github.com/evg4b/uncors/pull/3)

## [0.0.8 Release](https://github.com/evg4b/uncors/releases/tag/v0.0.8)

- [X] Disclaimer message
- [X] Mock responce from file
- [X] Mock response from file
- [X] Viper configuration
- [X] Multile CLI url mapping
- [X] Multiple CLI url mapping

## [0.0.8-beta Release](https://github.com/evg4b/uncors/releases/tag/v0.0.8-beta)

Expand All @@ -52,12 +52,14 @@

## Next Release

- [ ] Separated mock for each url mapping
- [ ] Static file serving
- [X] Static file serving [PR](https://github.com/evg4b/uncors/pull/15)
- [X] Own error page for uncors internal errors
- [ ] Separated mock for each url mapping [PR](https://github.com/evg4b/uncors/pull/16)

## Future features

- [ ] Informative error messages - [PR](https://github.com/evg4b/uncors/pull/10)
- [ ] Occupied port handling
- [ ] Collecting all request/response to har file
- [ ] Response caching
- [ ] Content URl replacing (HTML, JSON, TEXT and other)
32 changes: 18 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,49 @@ require (
github.com/PuerkitoBio/purell v1.2.0
github.com/go-http-utils/headers v0.0.0-20181008091004-fed159eddc2a
github.com/go-playground/assert/v2 v2.2.0
github.com/go-playground/validator/v10 v10.12.0
github.com/gojuno/minimock/v3 v3.1.2
github.com/go-playground/validator/v10 v10.14.0
github.com/gojuno/minimock/v3 v3.1.3
github.com/gorilla/mux v1.8.0
github.com/hashicorp/go-version v1.6.0
github.com/mitchellh/mapstructure v1.5.0
github.com/pseidemann/finish v1.2.0
github.com/pterm/pterm v0.12.57
github.com/pterm/pterm v0.12.62
github.com/samber/lo v1.38.1
github.com/spf13/afero v1.9.5
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.2
golang.org/x/net v0.8.0
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.8.4
golang.org/x/net v0.10.0
)

require (
atomicgo.dev/cursor v0.1.1 // indirect
atomicgo.dev/keyboard v0.2.9 // indirect
atomicgo.dev/schedule v0.0.2 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/gookit/color v1.5.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/leodido/go-urn v1.2.2 // indirect
github.com/lithammer/fuzzysearch v1.1.5 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/lithammer/fuzzysearch v1.1.8 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 3826025

Please sign in to comment.