From 70712b9a87bac53f1f56f3b457e93886d627375a Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 7 Apr 2021 02:00:05 +1000 Subject: [PATCH] Ripped out unneeded stuff --- .github/workflows/docker.yml | 39 ---------- LICENSE | 11 --- configure-script.js | 135 ----------------------------------- package-lock.json | 1 - package.json | 1 - server/server.js | 3 +- test/dev-news-requests.rest | 33 --------- test/requests.rest | 54 -------------- 8 files changed, 1 insertion(+), 276 deletions(-) delete mode 100644 .github/workflows/docker.yml delete mode 100644 LICENSE delete mode 100644 configure-script.js delete mode 100644 test/dev-news-requests.rest delete mode 100644 test/requests.rest diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index 91af0cc..0000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: Publish Docker image -on: - release: - types: [ published ] - push: - tags: - - v1.* -jobs: - push_to_registry: - name: Push Docker Image to Docker Hub - runs-on: ubuntu-latest - steps: - - name: Check Out The Repo - uses: actions/checkout@v2 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Get Smart Tag - id: prepare - uses: Surgo/docker-smart-tag-action@v1 - with: - docker_image: krgamestudios/news-server - - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Push to Docker Hub - uses: docker/build-push-action@v2 - with: - push: true - tags: ${{ steps.prepare.outputs.tag }} - platforms: amd64,arm diff --git a/LICENSE b/LICENSE deleted file mode 100644 index be733db..0000000 --- a/LICENSE +++ /dev/null @@ -1,11 +0,0 @@ -Copyright (c) 2021 Kayne Ruse, KR Game Studios - -This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. - -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. - -3. This notice may not be removed or altered from any source distribution. diff --git a/configure-script.js b/configure-script.js deleted file mode 100644 index 9791617..0000000 --- a/configure-script.js +++ /dev/null @@ -1,135 +0,0 @@ -//setup -const readline = require('readline'); -const fs = require('fs'); -const crypto = require("crypto"); - -const uuid = (bytes = 16) => crypto.randomBytes(bytes).toString("hex"); - -const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout, - terminal: false -}); - -//manually promisify this (util didn't work) -const question = (prompt, def = null) => { - return new Promise((resolve, reject) => { - rl.question(`${prompt}${def ? ` (${def})` : ''}: `, answer => { - //loop on required - if (def === null && !answer) { - return resolve(question(prompt, def)); - } - - return resolve(answer || def); - }); - }); -}; - -//questions -(async () => { - //project configuration - const appName = await question('App Name', 'news'); - const appWebAddress = await question('Web Addr', `${appName}.example.com`); - const appPort = await question('App Port', '3100'); - - const appDBUser = await question('DB User', appName); - const appDBPass = await question('DB Pass', uuid()); - const dbRootPass = await question('DB Root Pass'); - - const appSecretAccess = await question('Access Token Secret', uuid(32)); - - const supportEmail = await question('Support Email', 'example@example.com'); - - //generate the files - const ymlfile = ` -version: '3' - -services: - ${appName}: - build: - context: . - ports: - - "${appPort}" - labels: - - "traefik.enable=true" - - "traefik.http.routers.${appName}router.rule=Host(\`${appWebAddress}\`)" - - "traefik.http.routers.${appName}router.entrypoints=websecure" - - "traefik.http.routers.${appName}router.tls.certresolver=myresolver" - - "traefik.http.routers.${appName}router.service=${appName}service@docker" - - "traefik.http.services.${appName}service.loadbalancer.server.port=${appPort}" - environment: - - WEB_PORT=${appPort} - - DB_HOSTNAME=database - - DB_DATABASE=${appName} - - DB_USERNAME=${appDBUser} - - DB_PASSWORD=${appDBPass} - - DB_TIMEZONE=Australia/Sydney - - QUERY_LIMIT=10 - - SECRET_ACCESS=${appSecretAccess} - networks: - - app-network - depends_on: - - database - database: - image: mariadb:latest - environment: - MYSQL_DATABASE: ${appName} - MYSQL_USER: ${appDBUser} - MYSQL_PASSWORD: ${appDBPass} - MYSQL_ROOT_PASSWORD: ${dbRootPass} - networks: - - app-network - volumes: - - ./mysql:/var/lib/mysql - - ./startup.sql:/docker-entrypoint-initdb.d/startup.sql:ro - traefik_${appName}: - container_name: ${appName}_traefik - image: "traefik:v2.4" - container_name: "traefik" - command: - - "--log.level=ERROR" - - "--api.insecure=false" - - "--providers.docker=true" - - "--providers.docker.exposedbydefault=false" - - "--entrypoints.websecure.address=:443" - - "--certificatesresolvers.myresolver.acme.tlschallenge=true" - - "--certificatesresolvers.myresolver.acme.email=${supportEmail}" - - "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json" - ports: - - "80:80" - - "443:443" - volumes: - - "./letsencrypt:/letsencrypt" - - "/var/run/docker.sock:/var/run/docker.sock:ro" - networks: - - app-network -networks: - app-network: - driver: bridge -`; - - const dockerfile = ` -FROM node:15 -WORKDIR "/app" -COPY package*.json ./ -COPY . /app -RUN npm install --production -EXPOSE ${appPort} -USER node -ENTRYPOINT ["bash", "-c"] -CMD ["sleep 10 && npm start"] -`; - - const sqlfile = ` -CREATE DATABASE IF NOT EXISTS ${appName}; -CREATE USER IF NOT EXISTS '${appDBUser}'@'%' IDENTIFIED BY '${appDBPass}'; -GRANT ALL PRIVILEGES ON ${appName}.* TO '${appDBUser}'@'%'; -`; - - fs.writeFileSync('docker-compose.yml', ymlfile); - fs.writeFileSync('Dockerfile', dockerfile); - fs.writeFileSync('startup.sql', sqlfile); -})() - .then(() => rl.close()) - .catch(e => console.error(e)) -; diff --git a/package-lock.json b/package-lock.json index 269e011..6eb92cf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,6 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "body-parser": "^1.19.0", "cors": "^2.8.5", "dotenv": "^8.2.0", "express": "^4.17.1", diff --git a/package.json b/package.json index 58fd942..9c68257 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,6 @@ }, "homepage": "https://github.com/krgamestudios/news-server#readme", "dependencies": { - "body-parser": "^1.19.0", "cors": "^2.8.5", "dotenv": "^8.2.0", "express": "^4.17.1", diff --git a/server/server.js b/server/server.js index fa7f507..e823067 100644 --- a/server/server.js +++ b/server/server.js @@ -5,11 +5,10 @@ require('dotenv').config(); const express = require('express'); const app = express(); const server = require('http').Server(app); -const bodyParser = require('body-parser'); const cors = require('cors'); //config -app.use(bodyParser.json()); +app.use(express.json()); app.use(cors()); //database connection diff --git a/test/dev-news-requests.rest b/test/dev-news-requests.rest deleted file mode 100644 index 12db194..0000000 --- a/test/dev-news-requests.rest +++ /dev/null @@ -1,33 +0,0 @@ -#Query -GET https://dev-news.eggtrainer.com/news HTTP/1.1 - -### - -#Publish -POST https://dev-news.eggtrainer.com/news HTTP/1.1 -Content-Type: application/json -Authorization: Bearer - -{ - "title": "Hello World", - "author": "Kayne Ruse", - "body": "Lorem ipsum." -} - -### - -#Edit -PATCH https://dev-news.eggtrainer.com/news/1 HTTP/1.1 -Content-Type: application/json -Authorization: Bearer - -{ - "title": "Goodnight World" -} - -### - -#Delete -DELETE https://dev-news.eggtrainer.com/news/1 HTTP/1.1 -Content-Type: application/json -Authorization: Bearer diff --git a/test/requests.rest b/test/requests.rest deleted file mode 100644 index 7563224..0000000 --- a/test/requests.rest +++ /dev/null @@ -1,54 +0,0 @@ -#Login to the auth-server -POST http://127.0.0.1:3200/auth/login HTTP/1.1 -Content-Type: application/json - -{ - "email": "kayneruse@gmail.com", - "password": "helloworld" -} - -### - -#Refresh from the auth-server -POST http://127.0.0.1:3200/auth/token HTTP/1.1 -Content-Type: application/json - -{ - "token": "" -} - -### - -#Query -GET http://127.0.0.1:3100/news HTTP/1.1 - -### - -#Publish -POST http://127.0.0.1:3100/news HTTP/1.1 -Content-Type: application/json -Authorization: Bearer - -{ - "title": "Hello World", - "author": "Kayne Ruse", - "body": "Lorem ipsum dolor sit amet..." -} - -### - -#Edit -PATCH http://127.0.0.1:3100/news/5 HTTP/1.1 -Content-Type: application/json -Authorization: Bearer - -{ - "title": "Goodnight World" -} - -### - -#Delete -DELETE http://127.0.0.1:3100/news/4 HTTP/1.1 -Content-Type: application/json -Authorization: Bearer