Skip to content

Commit

Permalink
Merge pull request #45 from irensaltali/develop
Browse files Browse the repository at this point in the history
doc: Update README.md and add CONTRIBUTING.md
  • Loading branch information
irensaltali committed Mar 2, 2024
2 parents e522a34 + 8c871ad commit 25db0a2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 188 deletions.
17 changes: 17 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Contributing to Serverless API Gateway

Serverless API Gateway is an open project, and you can contribute to it in many ways. You can help with ideas, code, or documentation. We appreciate any efforts that help us to make the project better.

Thank you!

## Legal Info

When you open your first pull-request to ClickHouse repo, a bot will invite you to accept ClickHouse Individual CLA (Contributor License Agreement). It is a simple few click process. For subsequent pull-requests the bot will check if you have already signed it and won't bother you again.

## How to Contribute

Your contributions are what make the Serverless API Gateway an even better API management solution! If you have suggestions for new features, notice a bug, or want to improve the code, please take the following steps:

1. Fork the repository.
2. Implement your changes on a new branch.
3. Submit a pull request with a clear description of your improvements.
190 changes: 2 additions & 188 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,198 +21,12 @@ Welcome to the Serverless API Gateway, an innovative tool designed to streamline

APIs are pivotal in the landscape of modern applications, but they bring forth a unique set of challenges regarding security, routing, and overall management. The Serverless API Gateway emerged from the need to address these issues in a reliable, manageable, and cost-effective way. Built upon Cloudflare's serverless infrastructure, this project provides developers with a lightweight yet robust toolkit that adapts to the unpredictability of internet scale and traffic. Our mission is to empower developers to securely and efficiently manage their APIs without the overhead of managing infrastructure.

## Getting Started

To start using the Serverless API Gateway:

1. Clone the repository:
```bash
git clone https://github.com/irensaltali/serverlessapigateway.git
```

1. Install dependencies:
```bash
cd worker
npm install
```

1. Configure your routes, CORS settings, and JWT secrets within the provided configuration files.

2. Deploy your workers to Cloudflare using the command:
```bash
wrangler publish
```

(For detailed setup and usage instructions, please see the Cloudflare Workers' [documentation](https://developers.cloudflare.com/workers)).

## JSON Configuration Guide

This document provides detailed guidance on how to use the provided JSON configuration for setting up and managing your application's server, CORS (Cross-Origin Resource Sharing) settings, authorization, and API paths.

### Configuration Overview

The JSON configuration is divided into several key sections:

- `servers`: Defines server aliases and URLs.
- `cors`: Configures Cross-Origin Resource Sharing settings.
- `authorizer`: Sets up authorization parameters.
- `paths`: Specifies API endpoints and their behaviors.


### Servers

The `servers` section is an array of objects where each object represents a server configuration.

- `alias`: A shorthand name for the server.
- `url`: The full URL to access the server.

#### Example

```json
"servers": [
{
"alias": "ngrok",
"url": "https://a8ee-176-88-98-23.ngrok-free.app"
}
]
```
### CORS

The CORS section defines the CORS policy for your application.

- `allow_origins`: Specifies which origins are allowed.
- `allow_methods`: Lists the HTTP methods allowed.
- `allow_headers`: Headers that are allowed in requests.
- `expose_headers`: Headers that are exposed in responses.
- `allow_credentials`: Indicates whether credentials are supported.
- `max_age`: Specifies the cache duration for preflight requests.

#### Example

```json
"cors": {
"allow_origins": [
"https://example.com",
"https://example2.com"
],
"allow_methods": [
"GET",
"POST",
"PUT",
"DELETE"
],
"allow_headers": [
"Content-Type",
"Authorization"
],
"expose_headers": [
"Content-Type",
"Authorization"
],
"allow_credentials": true,
"max_age": 86400
}
```

### Authorizer

The authorizer section configures the authorization mechanism. ServerlessAPIGateway currently supports JWT (JSON Web Token) based authorization with HS256 algorithm.

- `type`: Type of authorization (e.g., JWT).
- `secret`: Secret key for authorization.
- `algorithm`: Algorithm used for token validation.
- `audience`: Intended audience of the token.
- `issuer`: The issuer of the token.

#### Example

```json
{
"authorizer": {
"type": "jwt",
"secret": "{YOUR_SECRET_KEY}",
"algorithm": "HS256",
"audience": "opensourcecommunity",
"issuer": "serverlessapigw"
},
}
```


### Paths

The paths section is an array of objects where each object represents an API endpoint configuration.

- `method`: HTTP method (GET, POST, etc.).
- `path`: URL path of the API endpoint.
- `integration`: Server integration settings.
- `auth`: Indicates if the path requires authentication.
- `mapping`: Defines mappings for headers and query parameters.
- `variables`: Sets variables used in the endpoint.
- `response`: Specifies the response structure for the endpoint.

## Deployment

You can deploy the Serverless API Gateway to Cloudflare Workers using the provided `wrangler.toml` configuration file. After setting up your configuration, you can deploy your workers using the following command:

```bash
wrangler publish
```

If you like to use GitHub actions for deployment here is is way for that. Add 'api-config.json' and 'wrangler.toml' file to your repository and add the following secrets to your repository.

```
── .githib
│ ├── workflows
│ │ ├── deploy-serverless-api-gateway.yml
├── api-config.json
└── wrangler.toml
```

deploy-serverless-api-gateway.yml
```yaml
name: Deploy Serverless API Gateway

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Prepare Serverless API Gateway Config for Deployment
uses: irensaltali/serverlessapigateway-action@v0.0.4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
configJson: './api-config.json'
wranglerToml: './wrangler.toml'
versionTag: 'v1.0.1'
- name: Deploy to Cloudflare Workers
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
workingDirectory: "worker"
```


## Usage Guidelines

- Ensure that each section of the JSON is correctly formatted according to the [schema](./worker/src/api-config.schema.json).
- Modify the configuration to suit your application's requirements.
- The configuration should be loaded and parsed by your application at startup.

For detailed setup and usage instructions, please see the [Serverless API Gateway documentation](https://docs.serverlessapigateway.com).

## Contributing

Your contributions are what make the Serverless API Gateway an even better API management solution! If you have suggestions for new features, notice a bug, or want to improve the code, please take the following steps:

1. Fork the repository.
2. Implement your changes on a new branch.
3. Submit a pull request with a clear description of your improvements.
If you want to contribute to the project, you can start by checking the [contributing guidelines](CONTRIBUTING.md).


## Acknowledgments
Expand Down

0 comments on commit 25db0a2

Please sign in to comment.