Note
This is the repository that handles dynamic features for the Conestoga Computer Science Club's website. It should be maintained by a member of the current club leadership, and everybody is welcome to contribute! Check out the site's repository or the actual site.
To get started, clone this repository using the following command:
git clone https://github.com/stogacs/Website-Backend
After cloning the repository, you need to make some configurations to set up the server.
- Rename the
.env.example
file to.env
. - Replace the sample values in the
.env
file with actual values from the Discord Developer Portal or generate new ones as needed.
- Rename the
config.json.example
file toconfig.json
. - Replace the sample values in the
config.json
file with actual values from the Discord Developer Portal or generate new ones as needed. - If you have an SSL certificate, make sure to point the three components of your SSL certificate to the files on your filesystem. If you don't have an SSL certificate, you can generate a free one with Let's Encrypt.
- Ensure that the
port
value for HTTPS is set to443
to avoid potential issues with school firewalls. Please note that using HTTPS is required for the server to function properly; otherwise, it might be blocked by the client's browser.
The data for the shop is stored in the data
folder. The structure of the data
folder is as follows:
data
store.json
users.json
assets
shekels_user.png
(User icon for webhooks)shop_0.png
shop_1.png
(An image for each item in the shop with thehas_image
flag set to true)
If you don't have any data, you'll want to create new store.json
and user.json
files. Below is an example of a store.json
file with two items:
{
"items": {
"0": {
"hasImg": true,
"id": 0,
"title": "Shekel Multiplier (2x)",
"description": "For the next 14 days, receive twice the shekels.",
"price": 35,
"max_quantity": 1,
"type": "MULTI",
"effect": [
{
"type": "multiplier",
"value": 2
}
],
"expires_after": 1209600000
},
"1": {
"hasImg": true,
"id": 1,
"title": "Choose Your Candy",
"description": "Pick the next candy to be purchased for the club. Must be approved by leadership.",
"price": 15,
"type": "MANUAL",
"last_purchase_stamp": null
}
}
}
The expires_after
is an optional property that defines how long the item will remain in a user's inventory before being removed (it is a timestamp in milliseconds). The expires_at
is an optional property that defines when the item will be removed from the store (it's a UNIX timestamp in milliseconds). You can generate timestamps with tools like Epoch Converter.
Warning
This file contains properties that are not currently used and are reserved for future features.
[
{
"name": "User Two",
"id": "c91a57ef-eb30-4f53-b56c-5f9f4c237404",
"admin": false,
"Shekels": 10,
"email": "[email protected]",
"displayName": "Joe Sharick",
"tokens": []
},
{
"name": "User Two",
"id": "d8a468de-249d-42f2-8b77-8f904e3d399c",
"admin": false,
"Shekels": 20,
"email": "[email protected]",
"discordID": "123456789012345678",
"displayName": "",
"tokens": []
}
]
These are two users who have not signed in via Discord. The tokens
property is used to store sessions. The discordID
is an optional property to assist in identifying users who have signed in via Discord. If this is not present when the user does sign in via Discord, they will be asked to enter their name, and they will be matched to the user with the same name, or a new user will be created.
The admin
property allows the user to modify shekel balances and add/remove users.
Once you've configured the server, you must install node modules with the following command:
npm i
After installing the node modules, you can run the server with the following command:
npm run serve
Note
For hosting the server, you should use a program like pm2 to run the server on startup and keep it running.
All pull requests are welcome.