Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Nachwahl committed Apr 24, 2022
0 parents commit a6327c8
Show file tree
Hide file tree
Showing 48 changed files with 14,909 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/discord.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/mapv2.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
.git
**/*.js
**/*.map
**/*.md
keycloak.json
.env
24 changes: 24 additions & 0 deletions backend/.example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# GENERAL SETTINGS
#

LOGLEVEL=debug
WEBPORT=8899
SESSION_SECRET=cat_dancing_on_keyboard_goes_brrrrrrrrrrrrrrrrrrr

# This was inserted by `prisma init`:
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema

# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB (Preview) and CockroachDB (Preview).
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

DATABASE_URL="mysql://btebackend:verysecurepassw0rd@database:3306/btebackend"

#
# KEYCLOAK SETTINGS
#

KEYCLOAK_CLIENTID=clientid
KEYCLOAK_CLIENTSECRET=verysecretsecret
KEYCLOAK_URL=https://keycloak.instance/auth
7 changes: 7 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules/*
.env
*.map
*.js
.idea
package-lock.json
keycloak.json
16 changes: 16 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:latest
WORKDIR /app

COPY package*.json ./
COPY prisma ./prisma/

COPY . .

RUN npm install -g typescript && npm install
RUN npm install -g prisma
RUN npx prisma generate
RUN tsc

EXPOSE 8899

CMD ["node", "index.js"]
23 changes: 23 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Node Backend

``❗ Please place a keycloak.json inside the root folder of the project. See the example here: https://github.com/keycloak/keycloak-quickstarts/blob/latest/service-nodejs/keycloak.json``

# Start Developing
#### If you are using JetBrains WebStorm, look below under `Start Developing in WebStorm`

1. Clone this Repository (`git clone https://github.com/BuildTheEarth/website-node-backend.git`)
2. Compile the TS files to JS (`tsc` if not installed, run `npm install -g typescript`)
3. Start the server with `npm start`
4. 🎉 Start Coding

📌 All settings can be made in a `.env` file. (Just copy and rename the `.example.env`)


# Start Developing in WebStorm
1. Clone this Repository (`git clone https://github.com/BuildTheEarth/website-node-backend.git`)
2. Open your WebStorm settings (CTRL+ALT+S)
3. Enable the following checkbox ![](https://i.arvserver.xyz/webstorm64_S0SyJU6BhQ.png)
4. Start the server with `npm start`
5. 🎉 Start Coding

📌 All settings can be made in a `.env` file. (Just copy and rename the `.example.env`)
3 changes: 3 additions & 0 deletions backend/babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/preset-env"]
}
33 changes: 33 additions & 0 deletions backend/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: '3'

services:
backend:
image: bteweb/backend
environment:
- LOGLEVEL=${LOGLEVEL}
- WEBPORT=${WEBPORT}
- SESSION_SECRET=${SESSION_SECRET}
- DATABASE_URL=${DATABASE_URL}
- KEYCLOAK_CLIENTID=${KEYCLOAK_CLIENTID}
- KEYCLOAK_CLIENTSECRET=${KEYCLOAK_CLIENTSECRET}
- KEYCLOAK_URL=${KEYCLOAK_URL}
ports:
- ${WEBPORT}:${WEBPORT}
volumes:
- ./keycloak.json:/app/keycloak.json
depends_on:
- database
links:
- database
database:
image: mariadb:latest
environment:
MYSQL_DATABASE: "btebackend"
MYSQL_USER: "btebackend"
MYSQL_PASSWORD: "verysecurepassw0rd"
MARIADB_RANDOM_ROOT_PASSWORD: "yes"
volumes:
- backenddb:/var/lib/mysql

volumes:
backenddb:
4 changes: 4 additions & 0 deletions backend/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
echo "Waiting for the db to be fired up"
sleep 5
echo "Pushing schema to database"
npx prisma db push
19 changes: 19 additions & 0 deletions backend/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Core from './src/Core';

require('dotenv').config();

const core = new Core();
core.getLogger().info('Starting Polymap backend');
core.getLogger().info('\n\n@@@@@@@@@@@@,,,,,,,@@@@@@@@@@@\n'
+ '@&&&&&&.,,,,,,,,,, ,,,..&&&&&&\n'
+ '@&&&.,,, *********,,,,,,,,.&&&\n'
+ '@&.,,**************,,,,,,,,,.&\n'
+ '@.,,****** ******  *,,,,,,,,,*\n'
+ '.,,*********** ,***,,,,,,,,,,,\n'
+ '.,,,************., ,....,,,,,.\n'
+ '.,,,,**********.,,,,,,,,,,,,..\n'
+ '@.,,,,,,,,,,,,,, ,,,,,,,,,,,.*\n'
+ '@&.,,,,,,,,,,,,,,,, ,,,,,,,,.&\n'
+ '@&&&.,,,,,,,,,,,,,, ,,,,...&&&\n'
+ '@&&&&&&.////..,,.. ,,,..&&&&&&\n'
+ '');
46 changes: 46 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "polymap-backend",
"version": "1.0.0",
"description": "The polymapv2 backend",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "babel-node index.js",
"start-nodemon": "nodemon --exec babel-node index.js",
"start:migrate": "npx prisma migrate deploy && node index.js"
},
"author": "",
"devDependencies": {
"@babel/cli": "^7.14.3",
"@babel/core": "^7.14.5",
"@babel/node": "^7.14.5",
"@babel/preset-env": "^7.13.5",
"@types/express": "^4.17.11",
"@types/jsonwebtoken": "^8.5.2",
"@types/node": "^15.6.1",
"@types/validator": "^13.1.3",
"@typescript-eslint/eslint-plugin": "^4.27.0",
"@typescript-eslint/parser": "^4.27.0",
"eslint": "^7.29.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.23.4",
"prisma": "^3.9.2"
},
"dependencies": {
"@keycloak/keycloak-admin-client": "^17.0.0",
"@prisma/client": "^3.9.2",
"@types/express-session": "^1.17.4",
"body-parser": "^1.19.0",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"express-session": "^1.17.2",
"express-yup-middleware": "^1.1.3",
"jsonwebtoken": "^8.5.1",
"keycloak-connect": "^17.0.0",
"log4js": "^6.3.0",
"mariadb": "^2.5.3",
"reflect-metadata": "^0.1.13",
"rfdc": "^1.3.0",
"yup": "^0.32.11"
}
}
22 changes: 22 additions & 0 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}

model Region {
id String @id @default(uuid())
username String
description String
userUUID String
data String @db.Text
city String
area Int
createdAt DateTime @default(now())
}
66 changes: 66 additions & 0 deletions backend/src/Core.ts

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions backend/src/controllers/RegionsController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {Request, Response} from "express";
import Core from "../Core";

class RegionsController {

private core: Core;

constructor(core: Core) {
this.core = core;
}

public async getAllRegions(request: Request, response: Response) {
let regions = await this.core.getPrisma().region.findMany({
select: {
username: true,
data: true,
userUUID: true,
id: true
}
});
response.send(regions)
}
}

export default RegionsController
12 changes: 12 additions & 0 deletions backend/src/types/express.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {GrantProperties} from "keycloak-connect";

interface kAuth {
grant: any;
}
declare global {
namespace Express {
interface Request {
kauth: kAuth
}
}
}
30 changes: 30 additions & 0 deletions backend/src/util/KeycloakAdmin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import KcAdminClient from "@keycloak/keycloak-admin-client";
import Core from "../Core";

class KeycloakAdmin {
private kcAdminClient: KcAdminClient;
private core: Core;

constructor(core: Core) {
this.core = core;
this.kcAdminClient = new KcAdminClient({
baseUrl: process.env.KEYCLOAK_URL,
realmName: process.env.KEYCLOAK_REALM
})

}

public getKeycloakAdminClient() {
return this.kcAdminClient;
}

public async authKcClient() {
return await this.kcAdminClient.auth({
grantType: "client_credentials",
clientId: process.env.KEYCLOAK_CLIENTID,
clientSecret: process.env.KEYCLOAK_CLIENTSECRET,
});
}
}

export default KeycloakAdmin;
Loading

0 comments on commit a6327c8

Please sign in to comment.