graphql sandbox & server
This commit is contained in:
34
.dockerignore
Normal file
34
.dockerignore
Normal file
@@ -0,0 +1,34 @@
|
||||
# Include any files or directories that you don't want to be copied to your
|
||||
# container here (e.g., local build artifacts, temporary files, etc.).
|
||||
#
|
||||
# For more help, visit the .dockerignore file reference guide at
|
||||
# https://docs.docker.com/engine/reference/builder/#dockerignore-file
|
||||
|
||||
**/.classpath
|
||||
**/.dockerignore
|
||||
**/.env
|
||||
**/.git
|
||||
**/.gitignore
|
||||
**/.project
|
||||
**/.settings
|
||||
**/.toolstarget
|
||||
**/.vs
|
||||
**/.vscode
|
||||
**/.next
|
||||
**/.cache
|
||||
**/*.*proj.user
|
||||
**/*.dbmdl
|
||||
**/*.jfm
|
||||
**/charts
|
||||
**/docker-compose*
|
||||
**/compose*
|
||||
**/Dockerfile*
|
||||
**/node_modules
|
||||
**/npm-debug.log
|
||||
**/obj
|
||||
**/secrets.dev.yaml
|
||||
**/values.dev.yaml
|
||||
**/build
|
||||
**/dist
|
||||
LICENSE
|
||||
README.md
|
||||
5
.env.example
Normal file
5
.env.example
Normal file
@@ -0,0 +1,5 @@
|
||||
DB_HOST=iceberg-gaming.com
|
||||
DB_PORT=3306
|
||||
DB_USERNAME=user
|
||||
DB_PASSWORD=pass
|
||||
DB_DATABASE=dbname
|
||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
.env
|
||||
32
Dockerfile
Normal file
32
Dockerfile
Normal file
@@ -0,0 +1,32 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
|
||||
# Comments are provided throughout this file to help you get started.
|
||||
# If you need more help, visit the Dockerfile reference guide at
|
||||
# https://docs.docker.com/engine/reference/builder/
|
||||
|
||||
ARG NODE_VERSION=16.17.0
|
||||
|
||||
FROM node:${NODE_VERSION}-alpine
|
||||
|
||||
# Use production node environment by default.
|
||||
ENV NODE_ENV production
|
||||
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Download dependencies as a separate step to take advantage of Docker's caching.
|
||||
# Leverage a cache mount to /root/.npm to speed up subsequent builds.
|
||||
COPY package-lock.json package.json ./
|
||||
RUN --mount=type=cache,target=/root/.npm \
|
||||
npm ci --omit=dev
|
||||
|
||||
# Run the application as a non-root user.
|
||||
USER node
|
||||
|
||||
COPY server.js .
|
||||
|
||||
# Expose the port that the application listens on.
|
||||
EXPOSE 4000
|
||||
|
||||
# Run the application.
|
||||
CMD node server.js
|
||||
10
README.md
10
README.md
@@ -1 +1,11 @@
|
||||
# 17th-UnitTracker-API
|
||||
|
||||
```docker
|
||||
docker-compose up -d --build
|
||||
|
||||
OR
|
||||
|
||||
<!-- if running as basic container, uncomment the dotenv line in server.js -->
|
||||
docker build -t unit-tracker-api .
|
||||
docker run -p 4000:4000 unit-tracker-api
|
||||
```
|
||||
|
||||
17
docker-compose.yaml
Normal file
17
docker-compose.yaml
Normal file
@@ -0,0 +1,17 @@
|
||||
name: 17th-unittracker-api
|
||||
|
||||
services:
|
||||
server:
|
||||
env_file:
|
||||
- .env
|
||||
build:
|
||||
context: .
|
||||
environment:
|
||||
NODE_ENV: production
|
||||
DB_HOST: ${DB_HOST}
|
||||
DB_PORT: ${DB_PORT}
|
||||
DB_USERNAME: ${DB_USERNAME}
|
||||
DB_PASSWORD: ${DB_PASSWORD}
|
||||
DB_DATABASE: ${DB_DATABASE}
|
||||
ports:
|
||||
- 4000:4000
|
||||
1628
package-lock.json
generated
Normal file
1628
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
20
package.json
Normal file
20
package.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "17th-unittracker-api",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "node server.js"
|
||||
},
|
||||
"author": "IndigoFox",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@apollo/server": "^4.7.1",
|
||||
"db2graphql": "^0.12.0",
|
||||
"dotenv": "^16.0.3",
|
||||
"graphql": "^16.6.0",
|
||||
"knex": "^2.4.2",
|
||||
"mysql": "^2.18.1"
|
||||
}
|
||||
}
|
||||
45
server.js
Normal file
45
server.js
Normal file
@@ -0,0 +1,45 @@
|
||||
const knex = require('knex');
|
||||
const db2g = require('db2graphql');
|
||||
const { ApolloServer } = require('@apollo/server');
|
||||
const { startStandaloneServer } = require('@apollo/server/standalone');
|
||||
// dotenv - not used if running in docker compose
|
||||
// require('dotenv').config();
|
||||
|
||||
// get env variables
|
||||
const { DB_HOST, DB_PORT, DB_USERNAME, DB_PASSWORD, DB_DATABASE } = process.env;
|
||||
|
||||
const start = async (cb) => {
|
||||
|
||||
/**************************************/
|
||||
const api = new db2g('mariadb', knex({
|
||||
client: 'mysql',
|
||||
connection: {
|
||||
host: DB_HOST,
|
||||
port: DB_PORT,
|
||||
user: DB_USERNAME,
|
||||
password: DB_PASSWORD,
|
||||
database: DB_DATABASE
|
||||
}
|
||||
}));
|
||||
await api.connect(DB_DATABASE); // Connects to database and extracts database schema
|
||||
|
||||
// Get generated schema and resolvers
|
||||
const schema = api.getSchema();
|
||||
const resolvers = api.getResolvers();
|
||||
/**************************************/
|
||||
|
||||
// Create Apollo Server and start
|
||||
if (!schema) throw new Error('Error: empty schema');
|
||||
console.log(schema);
|
||||
const server = new ApolloServer({
|
||||
typeDefs: schema,
|
||||
resolvers,
|
||||
introspection: true,
|
||||
playground: true,
|
||||
});
|
||||
startStandaloneServer(server).then(({ url }) => {
|
||||
console.log(`🚀 Server ready at ${url}`);
|
||||
});
|
||||
}
|
||||
|
||||
start();
|
||||
Reference in New Issue
Block a user