Skip to content

Commit

Permalink
Merge pull request #59 from BuidlGuidl/staging
Browse files Browse the repository at this point in the history
Merge Staging
  • Loading branch information
Avelous authored Jul 25, 2024
2 parents 2e2aa69 + 1c5e846 commit 73fdee8
Show file tree
Hide file tree
Showing 17 changed files with 21,222 additions and 20 deletions.
20,934 changes: 20,934 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions packages/backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
.env
coverage
coverage.json
typechain
typechain-types
temp


39 changes: 39 additions & 0 deletions packages/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# syntax = docker/dockerfile:1

# Adjust NODE_VERSION as desired
ARG NODE_VERSION=20.11.0
FROM node:${NODE_VERSION}-slim as base

LABEL fly_launch_runtime="Node.js"

# Node.js app lives here
WORKDIR /app

# Set production environment
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
FROM base as build

# Install packages needed to build node modules
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential node-gyp pkg-config python-is-python3

# Install node modules
COPY --link package.json ./
RUN npm install

# Copy application code
COPY --link . .


# Final stage for app image
FROM base

# Copy built application
COPY --from=build /app /app

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD [ "npm", "run", "start" ]
17 changes: 8 additions & 9 deletions packages/backend/controllers/Admin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Game from "../models/Game";
import Invites from "../models/Invites";
import bcrypt from "bcrypt";
import { Request, Response } from "express";
import jwt from "jsonwebtoken";
import { ably } from "..";
import backendConfig from "../backend.config";
Expand Down Expand Up @@ -40,7 +39,7 @@ async function generateUniqueInvite(length: number) {
}
}

export const createGame = async (req: Request, res: Response) => {
export const createGame = async (req: any, res: any) => {
try {
const { diceCount, hiddenPrivateKey, mode, adminAddress } = req.body;

Expand All @@ -67,7 +66,7 @@ export const createGame = async (req: Request, res: Response) => {
}
};

export const restartWithNewPk = async (req: Request, res: Response) => {
export const restartWithNewPk = async (req: any, res: any) => {
try {
const { diceCount, hiddenPrivateKey, adminAddress } = req.body;
const { id } = req.params;
Expand Down Expand Up @@ -95,7 +94,7 @@ export const restartWithNewPk = async (req: Request, res: Response) => {
}
};

export const pauseGame = async (req: Request, res: Response) => {
export const pauseGame = async (req: any, res: any) => {
try {
const { id } = req.params;
const game = await Game.findById(id);
Expand All @@ -120,7 +119,7 @@ export const pauseGame = async (req: Request, res: Response) => {
}
};

export const resumeGame = async (req: Request, res: Response) => {
export const resumeGame = async (req: any, res: any) => {
try {
const { id } = req.params;
const game = await Game.findById(id);
Expand Down Expand Up @@ -149,7 +148,7 @@ export const resumeGame = async (req: Request, res: Response) => {
}
};

export const endGame = async (req: Request, res: Response) => {
export const endGame = async (req: any, res: any) => {
try {
const { id } = req.params;
const game = await Game.findById(id);
Expand Down Expand Up @@ -179,7 +178,7 @@ export const endGame = async (req: Request, res: Response) => {
}
};

export const changeGameMode = async (req: Request, res: Response) => {
export const changeGameMode = async (req: any, res: any) => {
try {
const { id } = req.params;
const { mode } = req.body;
Expand Down Expand Up @@ -211,7 +210,7 @@ export const changeGameMode = async (req: Request, res: Response) => {
}
};

export const kickPlayer = async (req: Request, res: Response) => {
export const kickPlayer = async (req: any, res: any) => {
try {
const { id } = req.params;
const { playerAddress } = req.body;
Expand Down Expand Up @@ -241,7 +240,7 @@ export const kickPlayer = async (req: Request, res: Response) => {
}
};

export const varyHiddenPrivatekey = async (req: Request, res: Response) => {
export const varyHiddenPrivatekey = async (req: any, res: any) => {
try {
const { id } = req.params;
const { hiddenPrivateKey, diceCount } = req.body;
Expand Down
3 changes: 1 addition & 2 deletions packages/backend/controllers/Player.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import Game from "../models/Game";
import { Response, Request } from "express";
import jwt from "jsonwebtoken";
import { ably } from "..";
import backendConfig from "../backend.config";

const JWT_SECRET = process.env.JWT_SECRET || backendConfig.jwt_secret;

export const join = async (req: Request, res: Response) => {
export const join = async (req: any, res: any) => {
try {
const { inviteCode, playerAddress } = req.body;
const game = await Game.findOne({ inviteCode });
Expand Down
22 changes: 22 additions & 0 deletions packages/backend/fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# fly.toml app configuration file generated for pkdice-backend on 2024-07-25T12:07:55+01:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'pkdice-backend'
primary_region = 'ams'

[build]

[http_service]
internal_port = 3000
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
processes = ['app']

[[vm]]
memory = '1gb'
cpu_kind = 'shared'
cpus = 1
3 changes: 1 addition & 2 deletions packages/backend/middleware/auth.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import jwt from "jsonwebtoken";
import { Request, Response } from "express";
import backendConfig from "../backend.config";

const JWT_SECRET = process.env.JWT_SECRET || backendConfig.jwt_secret;

export const verifyToken = async (req: Request, res: Response, next: () => void) => {
export const verifyToken = async (req: any, res: any, next: () => void) => {
try {
let token = req.header("Authorization");

Expand Down
7 changes: 7 additions & 0 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@
"ts-node": "^10.9.1"
},
"devDependencies": {
"@flydotio/dockerfile": "^0.5.8",
"@types/bcrypt": "^5.0.0",
"@types/cors": "^2.8.14",
"@types/eslint": "^9",
"@types/express": "^4.17.18",
"@types/jsonwebtoken": "^9.0.3",
"@types/node": "^20.4.2",
"@typescript-eslint/eslint-plugin": "latest",
"@typescript-eslint/parser": "latest",
"eslint": "^8.15.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"types": "^0.1.1",
"typescript": "^5.1.6"
}
Expand Down
14 changes: 10 additions & 4 deletions packages/backend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
"compilerOptions": {
"target": "es2020",
"target": "ES2020",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
"typeRoots": ["./types", "./node_modules/@types"],
"paths": {
"~~/*": ["./*"]
}
},
"include": ["**/*.ts", "types/**/*.ts"],
"exclude": ["node_modules"]
}
1 change: 1 addition & 0 deletions packages/backend/tsconfig.tsbuildinfo

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions packages/backend/types/bcrypt.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare module "bcrypt";

1 change: 1 addition & 0 deletions packages/backend/types/cors.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'cors';
1 change: 1 addition & 0 deletions packages/backend/types/express.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'express';
1 change: 1 addition & 0 deletions packages/backend/types/jsonwebtoken.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'jsonwebtoken';
2 changes: 1 addition & 1 deletion packages/backend/vercel.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": 2,
"name": "dice-demo-backend",
"name": "pkdice-backend",
"builds": [
{
"src": "index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/server.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const serverConfig = {
isLocal: false,
localUrl: "http://localhost:6001",
liveUrl: "https://dicedemo-backend.fly.dev",
liveUrl: "https://pkdice-backend.fly.dev",
ably_api_key: "Fbq6sA.xC_GgQ:a9uQJKCunyvMmh1nVvcZaZFuZw_2LYbcHvTno5uPV5c",
};

Expand Down
Loading

0 comments on commit 73fdee8

Please sign in to comment.