Skip to content

Commit

Permalink
Publish API
Browse files Browse the repository at this point in the history
  • Loading branch information
MELVARDEV committed Jan 13, 2022
1 parent 00ac405 commit 77b5e89
Show file tree
Hide file tree
Showing 7 changed files with 1,703 additions and 0 deletions.
22 changes: 22 additions & 0 deletions API/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

# Use the official lightweight Node.js 14 image.
# https://hub.docker.com/_/node
FROM node:16.4-slim
# Create and change to the app directory.
WORKDIR /usr/src/app

# Copy application dependency manifests to the container image.
# A wildcard is used to ensure copying both package.json AND package-lock.json (when available).
# Copying this first prevents re-running npm install on every code change.
COPY package*.json ./

# Install production dependencies.
# If you add a package-lock.json, speed your build by switching to 'npm ci'.
# RUN npm ci --only=production
RUN npm install --only=production

# Copy local code to the container image.
COPY . ./

# Run the web service on container startup.
CMD [ "node", "index.js" ]
10 changes: 10 additions & 0 deletions API/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Riot Games API is rate-limited and needs an authorized API key to access the limited endpoints. This inelegant code allows requests to be cached to a database, avoiding rate-limiting blocks without exposing the API key.

I am publishing this API source code for transparency reasons only and don't guarantee that it will work in case you want to deploy it yourself.
In case you do, though, you need to include the following environment variables:
"riot_api_key", "DB_CONNECT"

Riot Games API key can be obtained here (need to request full access key to increase rate-limiting):
https://developer.riotgames.com/

"DB_CONNECT" is your MongoDB connection string.
20 changes: 20 additions & 0 deletions API/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const express = require("express");
const app = express();
var bodyParser = require("body-parser");
const mongoose = require("mongoose");
require("dotenv").config();

mongoose.connect(process.env.DB_CONNECT, { useNewUrlParser: true }, () => {
console.log("Connected to the database");
});

// import routes
const riotRoute = require("./routes/Riot");

// use routes
app.use("/riot", riotRoute);

const port = process.env.PORT || 8080;
app.listen(port, () => {
console.log(`nodejs: listening on port ${port}`);
});
19 changes: 19 additions & 0 deletions API/model/leagueApiCache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const mongoose = require("mongoose");

const cacheSchema = new mongoose.Schema({
jsonString: {
type: String,
},
timeFetched: {
type: Date,
},
endPoint: {
type: String,
},
region: {
type: String,
},
name: { type: String },
});

module.exports = mongoose.model("leagueApiCache", cacheSchema);
Loading

0 comments on commit 77b5e89

Please sign in to comment.