Skip to content

Commit ba38633

Browse files
author
Athaariq Ardhiansyah
committed
Initial Commit
0 parents  commit ba38633

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+13024
-0
lines changed

.dockerignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Unecessary directories inside docker container
2+
demo/
3+
test/
4+
5+
# Unecessary files inside docker container
6+
README.md
7+
load_test.go
8+
Makefile
9+
test-cert.pem
10+
test-key.key
11+
12+
# Compiled files
13+
build/
14+
kuda
15+
16+
# Hidden files
17+
.editorconfig
18+
.gitignore
19+
.git

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
10+
[{Makefile,Dockerfile}]
11+
indent_style = tab
12+
indent_size = 4
13+
insert_final_newline = false

.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Generated file at WSL
2+
*:Zone.Identifier
3+
**/*:Zone.Identifier
4+
5+
# Generated file at Mac
6+
.DS_STORE
7+
**/.DS_STORE
8+
9+
# Generated file at Windows XP
10+
Thumbs.db
11+
**/Thumbs.db
12+
13+
# Compiled
14+
build/
15+
kuda
16+
kuda.exe
17+
18+
# Front-end modules and compiled directory
19+
**/node_modules/
20+
**/dist/
21+
**/build/
22+
23+
# Logs
24+
*.log
25+
**/*.log

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language: go
2+
3+
go:
4+
- 1.3.x
5+
- 1.5.x
6+
- master
7+
8+
script: make test

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM golang:1-alpine
2+
3+
COPY . /usr/src
4+
WORKDIR /usr/src
5+
RUN go build -o ../bin
6+
7+
ENV KUDA_PUBLIC_DIR "/srv"
8+
ENV KUDA_DOMAIN "localhost"
9+
ENV KUDA_PORT "8080"
10+
ENV KUDA_ORIGINS ""
11+
ENV KUDA_PORT_TLS ""
12+
ENV KUDA_CERT ""
13+
ENV KUDA_KEY ""
14+
15+
CMD kuda ${KUDA_PUBLIC_DIR} --domain=${KUDA_DOMAIN} --port=${KUDA_PORT} --origins=${KUDA_ORIGINS} --portTLS=${KUDA_PORT_TLS} --cert=${KUDA_CERT} --key=${KUDA_KEY}

LICENSE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Released under MIT License
2+
3+
Copyright (c) 2020 Athaariq Ardhiansyah.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Makefile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
all: clean win_x64 win_x32 linux_x64 linux_x32 linux_arm64 linux_arm32 mac
2+
3+
.PHONY: test demo
4+
5+
demo:
6+
rm -rf demo/dist
7+
cd demo && npm install && npm run build
8+
go build
9+
./kuda demo/dist
10+
11+
test:
12+
go test
13+
14+
clean:
15+
rm -f kuda
16+
rm -rf build/*
17+
rm -rf demo/dist
18+
19+
win_x64:
20+
GOOS=windows GOARCH=amd64 go build -o build/kuda-win_x64.exe
21+
22+
win_x32:
23+
GOOS=windows GOARCH=386 go build -o build/kuda-win_x32.exe
24+
25+
linux_x64:
26+
GOOS=linux GOARCH=amd64 go build -o build/kuda-linux_x64
27+
28+
linux_x32:
29+
GOOS=linux GOARCH=386 go build -o build/kuda-linux_x32
30+
31+
linux_arm64:
32+
GOOS=linux GOARCH=arm64 go build -o build/kuda-linux_arm64
33+
34+
linux_arm32:
35+
GOOS=linux GOARCH=arm go build -o build/kuda-linux_arm32
36+
37+
mac:
38+
GOOS=darwin GOARCH=amd64 go build -o build/kuda-mac

README.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Kuda Web Server
2+
3+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4+
[![Open Issues](https://img.shields.io/github/issues-raw/Thor-x86/kuda)](https://github.com/Thor-x86/kuda/issues)
5+
[![Open Pull Request](https://img.shields.io/github/issues-pr-raw/Thor-x86/kuda)](https://github.com/Thor-x86/kuda/pulls)
6+
[![Unit Test Result](https://img.shields.io/travis/Thor-x86/kuda)](https://travis-ci.org/Thor-x86/kuda)
7+
8+
9+
Fast and concurrent in-memory web server. It compress static files with [gzip](https://en.wikipedia.org/wiki/Gzip), put them into RAM, and serve them as a normal web server. So Dev/Ops don't have to worry about storage speed, just focus on networking matter.
10+
11+
The best use case is serving Single Page Application (SPA) like [React](https://reactjs.org/), [Vue](https://vuejs.org/), and [Angular](https://angular.io/).
12+
13+
Special thanks to [fasthttp](https://github.com/valyala/fasthttp) and contributors for making kuda possible 🤘
14+
15+
## How to use
16+
17+
```
18+
USAGE:
19+
kuda [arguments] <public_root_directory>
20+
21+
ARGUMENTS:
22+
--port=... : TCP Port to be listened (default: "8080")
23+
--origins=... : Which domains to be allowed by CORS policy (default: "")
24+
--port-tls=... : Use this to listen for HTTPS requests (default: "")
25+
--domain=... : Required to redirect from http to https (default: "localhost")
26+
--cert=... : SSL certificate file, required if "--port-tls" specified
27+
--key=... : SSL secret key file, required if "--port-tls" specified
28+
```
29+
30+
## Usage Example
31+
32+
Let's say you're now in a directory with `kuda` executable and `my-app` as your react app project.
33+
34+
```
35+
cd my-app
36+
npm run build
37+
cd ..
38+
39+
./kuda my-app/build --port=8000 --origins=localhost:9000
40+
```
41+
42+
After executed, it will put everything inside `my-app/build` into RAM and serve at port 8000. Beside of that, we're assuming the API backend runs on port 9000. Thus, we have to add it as allowed origins with `--origins=...` flag to prevent [CORS Origin](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) problem.
43+
44+
### How about SSL?
45+
46+
Now we have same directory as above with `cert.pem` and `secret.key` inside of it.
47+
48+
```
49+
./kuda my-app/build --port=8000 --origins=localhost:9000 --port-tls=8090 --domain=localhost --cert=cert.pem --key=secret.key
50+
```
51+
52+
The `localhost:8000` is considered using HTTP protocol. So every connection coming to that port will be redirected to `https://localhost:8090`.
53+
54+
55+
### Serving Production App
56+
57+
In production environment, assuming you have `www.my-domain.com`, it will be like:
58+
59+
```
60+
sudo ./kuda my-app/build --port=80 --origins=localhost:9000 --port-tls=443 --domain=www.my-domain.com --cert=/etc/ssl/certs/my-domain.pem --key=/etc/ssl/private/my-domain.key
61+
```
62+
63+
## With Docker
64+
65+
Mostly, we deploy web app with docker and kubernetes (for orchestration). In order to do that, use this commands.
66+
67+
```
68+
docker pull kuda:latest
69+
docker run --name kuda-demo --volume my-compiled-webapp:/srv -p 8080:8080 --rm kuda:latest
70+
```
71+
72+
Where `my-compiled-webapp` is your directory with compiled app inside. **NEVER EVER** point project root directory as public directory, otherwise your machine will run out of memory very shortly!
73+
74+
## With Docker Compose
75+
76+
I would recommend you to use Docker Compose instead of plain Docker for sake of maintainability. This is an example of `docker-compose.yml`:
77+
78+
```yml
79+
version: "3"
80+
81+
services:
82+
kuda:
83+
image: kuda:latest
84+
volumes:
85+
- ./my-compiled-webapp:/srv
86+
environment:
87+
KUDA_PUBLIC_DIR: "/srv"
88+
KUDA_DOMAIN: "localhost"
89+
KUDA_PORT: "8080"
90+
KUDA_ORIGINS: ""
91+
KUDA_PORT_TLS: ""
92+
KUDA_CERT: ""
93+
KUDA_KEY: ""
94+
ports:
95+
- 8080:8080
96+
```
97+
98+
## Benchmark
99+
100+
I have no enough resource to benchmark Kuda Web Server myself. If you did benchmark and comparation with kuda, please let us know via **issue** section.
101+
102+
## Contribution
103+
104+
Anyone can contribute on this project. We welcome you to Pull Request or Open an Issue. To working on source code, you will require:
105+
- Linux or Mac preferred (Use [WSL](https://docs.microsoft.com/en-us/windows/wsl/install-win10) if you are Windows 10 user or [Cygwin](https://www.cygwin.com/) for older Windows)
106+
- Golang
107+
- Makefile
108+
- NPM (for demo)
109+
- Docker + Docker Compose (optional)
110+
111+
### Makefile Commands
112+
113+
There are things you can do with makefile on this project:
114+
- `make` -- Compile for all platforms and store them inside "build" directory
115+
- `make test` -- Run this everytime you want to pull request
116+
- `make clean` -- Removes all compiled files to reduce storage usage
117+
- `make demo` -- Run demonstration, go to `http://localhost:8080` on browser while running this command
118+
119+
### Security Report
120+
121+
To keep other users' security, please send email to [athaariqa@gmail.com](mailto://athaariqa@gmail.com) instead. **Do not** open issue for security report.

demo/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# kuda-demo
2+
3+
## Project setup
4+
```
5+
npm install
6+
```
7+
8+
### Compiles and hot-reloads for development
9+
```
10+
npm run serve
11+
```
12+
13+
### Compiles and minifies for production
14+
```
15+
npm run build
16+
```
17+
18+
### Lints and fixes files
19+
```
20+
npm run lint
21+
```
22+
23+
### Customize configuration
24+
See [Configuration Reference](https://cli.vuejs.org/config/).

demo/babel.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
presets: [
3+
'@vue/cli-plugin-babel/preset'
4+
]
5+
}

0 commit comments

Comments
 (0)