Small web server to send all messages from a Sendgrid inbound parse webhook to a MongoDB database
sudo apt update
sudo apt install python3-pip python3-dev build-essential libssl-dev libffi-dev python3-setuptools
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
sudo apt update
sudo apt install mongodb-org
sudo systemctl start mongod
sudo systemctl enable mongod
git clone https://github.com/jorivanee/sendgrid-inbound-to-mongo webhook && cd webhook
sudo apt install python3-venv
python3 -m venv prod
source prod/bin/activate
pip install -r requirements.txt
deactivate
cp config.example.json config.json
sudo nano config.json
sudo nano /etc/systemd/system/application.service
- Add the following lines:
[Unit]
Description=uWSGI instance to serve Webhook
After=network.target
[Service]
User=<your username>
Group=www-data
WorkingDirectory=/home/<your username>/webhook
Environment="PATH=/home/<your username>/webhook/prod/bin"
ExecStart=/home/<your username>/webhook/prod/bin/uwsgi --ini application.ini
[Install]
WantedBy=multi-user.target
sudo systemctl start application
sudo systemctl enable application
sudo apt install nginx
sudo nano /etc/nginx/sites-available/webhook
- Add the following lines:
server {
listen 80;
location / {
include uwsgi_params;
uwsgi_pass unix:/home/<your username>/webhook/application.sock;
}
}
sudo ln /etc/nginx/sites-available/webhook /etc/nginx/sites-enabled/webhook
sudo nginx -t
If the above command gives an output saying the configuration test is successful, proceedsudo service nginx restart
curl http://127.0.0.1
to verify if the installation worked