bram-dingelstad / neh

Licence: MIT license
The super small and simple nginx microservice/api maker!

Programming Languages

lua
6591 projects
shell
77523 projects

Projects that are alternatives of or similar to neh

vue-focus-keyboard
A keyboard component for Vue. Start to write immediately. No input element definition. Plug and play!
Stars: ✭ 63 (+85.29%)
Mutual labels:  plug-and-play
discord-economy-super
Easy and customizable economy module for your Discord bot.
Stars: ✭ 28 (-17.65%)
Mutual labels:  easy
discord.json
Discord.json | Make your own discord bot with json !
Stars: ✭ 27 (-20.59%)
Mutual labels:  easy
EzLocalization
Localize your flutter application quickly and easily.
Stars: ✭ 13 (-61.76%)
Mutual labels:  easy
mcthings
A Python framework for creating 3D scenes in Minecraft and Minetest
Stars: ✭ 44 (+29.41%)
Mutual labels:  easy
easymail
Easy way to install a mail server.
Stars: ✭ 60 (+76.47%)
Mutual labels:  easy
I-Do-Code
A workspace to sharpen you favourite programming language basics
Stars: ✭ 19 (-44.12%)
Mutual labels:  easy
duckphp
PHP框架,PHP Framework. keep PHP simple and fast. Laravel larva and Smarty is evil
Stars: ✭ 125 (+267.65%)
Mutual labels:  easy
zipline
A ShareX/file upload server that is easy to use, packed with features, and with an easy setup!
Stars: ✭ 215 (+532.35%)
Mutual labels:  easy
cpp-feather-ini-parser
Header only, simple, fast, templated - portable INI parser for ANSI C++.
Stars: ✭ 44 (+29.41%)
Mutual labels:  easy
Lua-Obfuscator
Obfuscate your lua code because it's so easy to steal!
Stars: ✭ 69 (+102.94%)
Mutual labels:  easy
Learning Resources
Beginner-friendly repository to make your first Pull Request and contribute to the open-source.
Stars: ✭ 40 (+17.65%)
Mutual labels:  easy
Tkinter-Designer
An easy and fast way to create a Python GUI 🐍
Stars: ✭ 4,697 (+13714.71%)
Mutual labels:  easy
CyberPunkNetrunner
Cyberpunk 2077 Netrunner Hacking Tool (Easy to use and install). Don't use it on illegal and malicious activity. Inspired by the game CyberPunk 2077 https://www.cyberpunk.net/
Stars: ✭ 69 (+102.94%)
Mutual labels:  easy
silly-android
Android plugins for Java, making core Android APIs easy to use
Stars: ✭ 40 (+17.65%)
Mutual labels:  easy
avo
Ruby on Rails application building framework
Stars: ✭ 907 (+2567.65%)
Mutual labels:  easy
DownloadRedditImages
Easily download all the images from any subreddit (also select sort_type if you want hot/top/new/controversial, and also sort_time day/week/month/year/all). Randomly select downloaded images and set as wallpaper, updating every 30 mins (or whenever you want duh)!
Stars: ✭ 66 (+94.12%)
Mutual labels:  easy
C-Complete-practice
This repository will contains C programs from beginners to advance level
Stars: ✭ 59 (+73.53%)
Mutual labels:  easy
Lang-app
Add a multi lang configuration to your WEB APP 'from scratch' [ANY FRAMEWORK, ANY PLUGIN, ANY API]
Stars: ✭ 15 (-55.88%)
Mutual labels:  easy
NeopixelBusFX
NeopixelBusFX plugin for ESPEasy
Stars: ✭ 27 (-20.59%)
Mutual labels:  easy

Neh

The super small and simple nginx microservice/api maker!



Ever wanted a quick webhook or a small API without writing an entire server?
Introducing Neh, a simple program executor for nginx.

With Neh you can:

  • Hook up a nginx location directive to any program or script
  • Receive the headers as env variables
  • Receive the request body as stdin
  • Write headers through file descriptor #3
  • Send commands like END_REQUEST to Neh on file descriptor #4
  • Do just about anything you want for an endpoint, really fast!

And all of that with just two lines in your config!

Check out my blog post for more information!

Keep in mind that Neh is in alpha and should not be run in production

Getting started

Make sure your location directive of choice looks like this:

location /hooks/test {
   set $execute_file /home/user/script.sh; # The path to the script you want to execute
   content_by_lua_file /usr/lib/neh/neh.lua; # The path to Neh
}

Then create the script file:

cd
cat <<EOF > ./script.sh
#!/bin/bash
echo Hello world!
EOF
chmod +x ./script.sh

Quickly reload your nginx config and checking if its correct sudo nginx -t && sudo systemctl reload nginx Now if you go to http://example.com/hooks/test you will see: Hello world!.
Congratz! You just set up your first Neh!

Just make sure that www-data or whatever user is running your nginx instance can access the script!

Installing

You can install it through this simple oneliner:

curl https://raw.githubusercontent.com/oap-bram/neh/master/install.sh | sh

You can also inspect the install file if you want to.

More examples

Here are some more examples of what you can do with Neh.

GitHub webhook

I wrote an elaborate blog post with a nice example too with GitHub hooks, so check it out there!

Bluring an image

With the following script, Neh transform a sent image into a blurred one. (Given you have ImageMagick installed on your system)

#!/bin/bash
convert - -blur 0x10 - # Convert data from stdin, blur and write to stdout

You can post the file as following:

curl https://example.com/your/endpoint --data-binary @./image.jpg -o ./blurred.jpg

Returning random bits or a hash

With the following script, Neh get's some random bits and returns them as a response

#!/bin/bash
dd if=/dev/urandom bs=1K count=1 2>/dev/null

Or if you want a random (md5) hash:

dd if=/dev/urandom bs=1K count=1 2>/dev/null | md5sum | cut -d ' ' -f1

Return a webpage rendered by Ruby

headers_fd = IO.sysopen('/proc/self/fd/3', 'w')
headers = IO.new(headers_fd)

headers << "Content-Type: text/html\n"
headers.flush

print '<h1>Hello world</h1>'
print '<p>This is a webpage</p>'

Quickly save some data with Python

#!/usr/bin/env python
import sys

with open("/tmp/file.txt", "a") as file:
    for line in sys.stdin:
        file.write(line)

You can then write to the endpoint using the following curl:

curl -sL https://example.com/your/endpoint --data-binary '{"hello": "world"}'

Do you have some cool implementations? Please share them with me by sending me a friendly message!

Debugging

For debugging you can tail your nginx error.log usually found at /var/log/nginx/error.log. If you want to debug /usr/lib/neh/neh.lua use the included print version and/or take a look at the openresty docs.

Troubleshooting

I had some trouble installing it on some of my servers because of an error relating to posix.ctype. It has to do with some libraries not linking properly on some distros. Apply the solution here.

Contributing

Feel free to open a pull request or an issue if you want! If this gets out of hand I'll setup some structure using GitHub.

TODO

  • Comprehensive documentation
  • Unit testing to guarantee quality
  • Actual testing from developers/users for feedback
  • Friendly error messages in logs and in responses
  • Production guarantees

I could use all the help you can throw at me, so if you can help with the above let me know!

License

See the LICENSE for more details.


Sheep by MHD AZMI DWIPRANATA from the Noun Project

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].