diff --git a/.envdev b/.envdev new file mode 100644 index 0000000..c05b394 --- /dev/null +++ b/.envdev @@ -0,0 +1,8 @@ +WEB_PORT=3200 + +DB_HOSTNAME=database +DB_DATABASE=auth +DB_USERNAME=auth +DB_PASSWORD=venusaur +DB_TIMEZONE=Australia/Sydney + diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..ee3336a --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,36 @@ +name: Publish Docker image +on: + release: + types: [ published ] +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/auth-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/.gitignore b/.gitignore index 6704566..8a8628d 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,6 @@ dist # TernJS port file .tern-port + +# Docker generated files and folders +data/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..be733db --- /dev/null +++ b/LICENSE @@ -0,0 +1,11 @@ +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/README.md b/README.md index f619f3a..ec28d40 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # auth-server -An API centric auth server. + +An API centric auth server. Uses Sequelize and mariaDB by default. + + diff --git a/package.json b/package.json new file mode 100644 index 0000000..1e4c0d1 --- /dev/null +++ b/package.json @@ -0,0 +1,32 @@ +{ + "name": "auth-server", + "version": "1.0.0", + "description": "An API centric auth server. Uses Sequelize and mariaDB by default.", + "main": "server/server.js", + "scripts": { + "start": "node server/server.js", + "dev": "npm run watch:server", + "watch:server": "nodemon . --ext js,jsx,json --ignore 'node_modules/*'" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/krgamestudios/auth-server.git" + }, + "author": "Kayne Ruse", + "license": "ISC", + "bugs": { + "url": "https://github.com/krgamestudios/auth-server/issues" + }, + "homepage": "https://github.com/krgamestudios/auth-server#readme", + "dependencies": { + "body-parser": "^1.19.0", + "cors": "^2.8.5", + "dotenv": "^8.2.0", + "express": "^4.17.1", + "mariadb": "^2.5.2", + "sequelize": "^6.5.0" + }, + "devDependencies": { + "nodemon": "^2.0.7" + } +} diff --git a/server/auth/index.js b/server/auth/index.js new file mode 100644 index 0000000..5922d4d --- /dev/null +++ b/server/auth/index.js @@ -0,0 +1,10 @@ +const express = require('express'); +const router = express.Router(); + +//the routes +//TODO: import the routes here + +//basic route management +//TODO: define the routes here + +module.exports = router; diff --git a/server/database/index.js b/server/database/index.js new file mode 100644 index 0000000..7d01b93 --- /dev/null +++ b/server/database/index.js @@ -0,0 +1,12 @@ +const Sequelize = require('sequelize'); + +const sequelize = new Sequelize(process.env.DB_DATABASE, process.env.DB_USERNAME, process.env.DB_PASSWORD, { + host: process.env.DB_HOSTNAME, + dialect: 'mariadb', + timezone: process.env.DB_TIMEZONE, + logging: false +}); + +sequelize.sync(); + +module.exports = sequelize; \ No newline at end of file diff --git a/server/database/models/index.js b/server/database/models/index.js new file mode 100644 index 0000000..aabbaee --- /dev/null +++ b/server/database/models/index.js @@ -0,0 +1,3 @@ +module.exports = { + //TODO: models +}; \ No newline at end of file diff --git a/server/server.js b/server/server.js new file mode 100644 index 0000000..bef99d4 --- /dev/null +++ b/server/server.js @@ -0,0 +1,29 @@ +//environment variables +require('dotenv').config(); + +//create the server +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(cors()); + +//database connection +const database = require('./database'); + +//access the news +app.use('/auth', require('./auth')); + +//error on access +app.get('*', (req, res) => { + res.redirect('https://github.com/krgamestudios/auth-server'); +}); + +//startup +server.listen(process.env.WEB_PORT || 3200, (err) => { + console.log(`listening to localhost:${process.env.WEB_PORT || 3200}`); +});