NOTE: It was a good experience, but Nitrogen no longer runs in production. We at Allotrope hope that others can learn from the project, but we will not be accepting further contributions. Contact us directly at nitrogen@allotrope.xyz if you need data retrieved. We will provide a tool to decrypt your data without having to send us a password.
Hello! We're happy you're interested in viewing the source code of the Nitrogen project. Nitrogen uses a combination of Angular and Express. The production version is running here.
In order to clone this repository, you'll have to use --recursive
to clone submodules as well. The backend
directory is a separate submodule that points to the backend
branch, and if you don't clone recursively, the directory will be empty.
git clone https://github.com/allotropelabs/nitrogen.git --recursive
Before you run Nitrogen, development or not, you'll need to give the backend a file to store its data in. An empty one is provided (data.blank.json
), you need only copy it and name it data.json
(and restart the backend if it's already running).
Nitrogen features an admin panel, but to see it you'll have to set yourself as admin. There is currently no automatic way to do this if no admin already exists. Stop the backend if it's running, and edit the data.json
file. Find your account in the accounts
list and set isAdmin
to true
. Save and restart the backend and you should see the "Report Bug" button on the my-projects replaced by "Admin".
In order to support auto-update, you'll have to modify the config.json
. A blank one can be found at config.default.json
. Put any string as the secret
- the backend won't care, as it's using HMAC, which isn't picky about secrets. These are used to verify the payloads sent by the webhook you'll need to create (WebHook documentation).
Once you've decided on a secret, go to the settings of your repository, navigate to Webhooks, and create a new webhook. Set the URL to wherever you're putting Nitrogen, plus /api/github
.
For example, if you were hosting it on example.com:5015
, you'd put http://example.com:5015/api/github
there. Use https://
instead of http://
if you have a certificate. Set the content type to application/json
, set the secret to your secret you set in the JSON file, select "Just the push
event", and then uncheck "Active".
Once you create the webhook, GitHub will send a ping event to your API server. ping event successfully received
should be visible in the logs. Here are two common error messages you might see if you did something wrong:
Your config.json
secret is not the same as the one in the webhook. Fix this by either correcting your webhook or config.json
.
You didn't add your secret to the webhook. Fix this by taking the secret in your config.json
and adding it to the webhook.
Additionally, there is one more message you might see when you push:
This shouldn't be an error unless you're pushing to a branch other than master
. If you are, modify the branch
in config.json
to the name of the branch you're using. Either that or push to master
. We push to backend
and then to master
with every change.
I'm sure before you host it for production you're going to want to make a few changes. Those are easy if you use the development mode; using a terminal or IDE of your choice, run ng serve
in the root directory and ts-node index.ts
in the backend
directory. The front-end will automatically know it's in development and try to use the backend on port 5015 (by default).
I recommend setting the port
to 5015
in the config.json
(or config.default.json
, although that isn't .gitignore
d) so the frontend can communicate with the API. That or if you think running ng build
for every change and visiting the API port is cool, go ahead and do that.
This is all assuming you run npm install
in both the root and backend directories first, of course.
And I'm so sorry I brutally murdered DRY (Don't Repeat Yourself). It's mainly in api.service.ts
, but you can see it elsewhere too.
After you're done with development, you'll probably want a way to push it to production. I've provided an easy script to help with building the app and putting it where it should be in the backend so the backend can serve it correctly.
Basically, the backend serves the app
directory, and the /api
endpoint is hooked up to the API. build.sh
automatically builds Nitrogen for production and puts it where the backend expects it to be. That way the backend and frontend can run at the same time without managing 2 processes in production.
Nitrogen supports HTTPS using a certificate. You'll need to put two files, privatekey.pem
and certificate.crt
, in the backend
directory, and the backend will take care of the rest. Note that this requires port + 1
and port + 2
to also be available for servers to run on, although they will not be exposed to the outside world and are only used by the server running on port
to proxy connections (such as redirecting http to https).
You do not require these files. If you do not provide them, the backend will run on normal (insecure; unencrypted) HTTP.