• Stars
    star
    187
  • Rank 206,464 (Top 5 %)
  • Language
    Go
  • License
    Other
  • Created over 7 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

โฉ Hapttic is a simple HTTP server that forwards all requests to a shell script.

hapttic

What is this good for?

  • You want to run some code in response to a webhook, like a github push.
  • You have some code on your Raspberry Pi that you want to run from work (great in combination with ngrok).
  • That's pretty much it.

How does it work?

Hapttic listens for incoming HTTP connections. When it receives a connection, it dumps all relevant data (headers, path, parameters, the body and other stuff) into a JSON object and calls a bash script with this object as its parameters.

Isn't this just a reinvention of CGI?

The basic idea is pretty similar. The main advantage of hapttic is ease of setup with a simple Docker image that lets you quickly connect a shell script to a http endpoint.

Show me an example

First, create a request handler at ~/hapttic_request_handler.sh:

echo $1

Then run the following command to spin up the docker container that runs hapttic:

docker run --rm -p 8080:8080 -v ~/hapttic_request_handler.sh:/hapttic_request_handler.sh --name hapttic jsoendermann/hapttic -file "/hapttic_request_handler.sh"

Finally, run open http://localhost:8080 to see the output of your script.

Show me a more realistic example

REQUEST=$1
SECRET_TOKEN=$(jq -r '.Header."X-My-Secret"[0]' <(echo $REQUEST))

if [[ "$SECRET_TOKEN" != "SECRET" ]]; then
  echo "Incorrect secret token"
  exit -1
fi

curl https://www.example.com/api/call/in/response/to/webhook

This request handling script can be run with curl -H "X-My-Secret: SECRET" http://localhost:8080

The jsoendermann/hapttic Dockerfile includes jq and curl, if you need any other command in your request handling script, you should create your own image.

The Request JSON object

The JSON object your request handling script gets called with is a subset of Go's http.Request. It's defined in hapttic.go as marshallableRequest. For documentation on http.Request, see the official net/http page.

SSL Support

You can add encryption by putting an nginx proxy in front of it with a docker-compose file like so:

version: '3'

volumes:
  vhost:
  html:

services:
  nginx-proxy:
    restart: always
    image: jwilder/nginx-proxy
    ports:
      - 80:80
      - 443:443
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - /var/certs:/etc/nginx/certs:ro
      - vhost:/etc/nginx/vhost.d
      - html:/usr/share/nginx/html
    labels:
      - "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true"

  letsencrypt-nginx-proxy-companion:
    restart: always
    image: jrcs/letsencrypt-nginx-proxy-companion
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /var/certs:/etc/nginx/certs:rw
      - vhost:/etc/nginx/vhost.d
      - html:/usr/share/nginx/html

  hapttic:
    restart: always
    image: jsoendermann/hapttic
    environment:
      - VIRTUAL_HOST=hapttic.your.domain.com                                # Replace this
      - LETSENCRYPT_HOST=hapttic.your.domain.com                            # Replace this
      - [email protected]                                # Replace this
    volumes:
      - /my-request-handler.sh:/hapttic_request_handler.sh                  # Replace this
    command: ["-file", "/hapttic_request_handler.sh"]
    depends_on:
      - nginx-proxy
      - letsencrypt-nginx-proxy-companion

More Repositories

1

rn-section-list-get-item-layout

๐Ÿ”ฒ Easy getItemLayout props for react-native SectionLists.
TypeScript
212
star
2

semaphore-async-await

๐ŸŽŒ Promise based Semaphore suitable to be used with async/await.
TypeScript
99
star
3

MongoStyleGuide

๐Ÿ“— An opinionated guide to data modeling with MongoDB.
87
star
4

react-native-async-storage-dev-menu-item

๐ŸŽ›๏ธ Adds an option to your dev menu to console.log the contents of your AsyncStorage.
Java
87
star
5

react-native-settings-screen

โš™๏ธ A component that inflates an object describing your app's settings turning it into a beautiful component.
TypeScript
61
star
6

react-native-bouncy-view

A bouncy View.
JavaScript
12
star
7

mouette

๐Ÿฆ [WIP] Lint your MongoDB.
TypeScript
12
star
8

nibbana

๐Ÿ”Š [WIP] Analytics for react native. Keep complete control of your data and find out how your users use your app.
TypeScript
8
star
9

Lagou

โœ‹ A readable, commented Promise implementation for educational purposes.
JavaScript
7
star
10

ljsp

My BSc project, a compiler for Lisp that emits asm.js, C and LLVM IR written in Scala.
JavaScript
5
star
11

react-native-press-me-button

๐Ÿ‘‡ A button that screams "Press me!"
Java
4
star
12

defaultdict-proxy

A Proxy based JavaScript port of python's defaultdict.
JavaScript
3
star
13

guan

๐ŸŽบ Deployment pipelines for personal projects.
Rust
2
star
14

AdventOfCode

Rust
2
star
15

HotaruServer

A mobile app back-end framework.
JavaScript
2
star
16

ClozedForBusiness

๐Ÿ—ƒ๏ธ Create cloze deletion Anki cards while reading Chinese texts.
JavaScript
2
star
17

jsoendermann.github.io

My personal website.
HTML
2
star
18

algos-and-datastructures

TypeScript
2
star
19

backup-mongo-to-s3

Docker image that dumps, zips, encrypts and uploads your mongo db to s3 on a cron schedule.
Shell
2
star
20

hgql

๐Ÿ“ฅ A tiny, magic-free, hook-based graphql client library for React
TypeScript
2
star
21

argus

1
star
22

mongodb-auto-reconnect

Automatically reconnect to your MongoDb.
TypeScript
1
star
23

count-down-the-days

JavaScript
1
star
24

capsule

1
star
25

CraftingInterpreters

TypeScript
1
star
26

practice-grid

JavaScript
1
star
27

react-native-fresh-id

TypeScript
1
star
28

rustlings-solutions

Rust
1
star
29

fresh-id-node

TypeScript
1
star
30

gehirn

1
star
31

react-native-animated-text

Objective-C
1
star
32

EmojiCalendar

๐Ÿ“… Emojis for your menu bar.
Swift
1
star
33

niu

๐Ÿšง [wip] A socks proxy that sits in front of a parent proxy and learns which sites are inaccessible.
Rust
1
star
34

aftm

Code for the Automated Fortune Teller Machine.
Python
1
star
35

segmenting-trie

A trie implementation that segments strings into words.
TypeScript
1
star
36

music-theory-anki-decks

JavaScript
1
star
37

moeve

Rust
1
star
38

color-clock

HTML
1
star
39

random-merge

TypeScript
1
star
40

react-native-attention-grabber

โ€ผ๏ธ Grab your users' attention by wrapping your components in an AttentionGrabber.
TypeScript
1
star
41

react-native-async-storage-utils

JavaScript
1
star
42

ComponentGallery

๐ŸŽ† A gallery of the react native components I've written.
JavaScript
1
star
43

HotaruClient

The Hotaru JavaScript SDK.
TypeScript
1
star
44

ready-for-takeoff

Ruby
1
star