Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/arcade/.env
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
BCRYPT_SALT=10
COMPOSE_PROJECT_NAME=amp_clc6ep483045sou01045ac971
JWT_SECRET_KEY=Change_ME!!!
JWT_EXPIRATION=2d
PORT=3000
KAFKA_BROKERS=localhost:9092
KAFKA_ENABLE_SSL=false
KAFKA_CLIENT_ID=arcade-service
KAFKA_GROUP_ID=arcade-service
DB_USER=postgres
DB_PASSWORD=postgres
JWT_SECRET_KEY=Change_ME!!!
JWT_EXPIRATION=2d
DB_URL=postgres://admin:admin@localhost:5432/my-db
DB_USER=admin
DB_PASSWORD=admin
DB_PORT=5432
DB_URL=postgres://postgres:postgres@localhost:5432/postgres
DB_NAME=my-db
5 changes: 2 additions & 3 deletions packages/arcade/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.



/node_modules
/dist
.DS_Store
.DS_Store
4 changes: 2 additions & 2 deletions packages/arcade/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:19.1 AS base
FROM node:18.12.1 AS base

WORKDIR /app

Expand All @@ -14,7 +14,7 @@ COPY . .

RUN npm run build

FROM node:19.1 AS prod
FROM node:18.12.1 AS prod

WORKDIR /app

Expand Down
66 changes: 66 additions & 0 deletions packages/arcade/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<p align="right">
<a href="https://amplication.com" target="_blank">
<img alt="amplication-logo" height="70" alt="Amplication Logo" src="https://amplication.com/images/amplication-logo-purple.svg"/>
</a>
</p>

# Introduction

This service was generated with Amplication. The server-side of the generated project. This component provides the different backend services - i.e., REST API, GraphQL API, authentication, authorization, logging, data validation and the connection to the database. Additional information about the server component and the architecture around it, can be found on the [documentation](https://docs.amplication.com/guides/getting-started) site.

# Getting started

## Step 1: Configuration

Configuration for the server component can be provided through the use of environment variables. These can be passed to the application via the use of the `.env` file in the base directory of the generated service. Below a table can be found which show the different variables that can be passed - these are the variables which exist by default, through the use of plugins additional integrations could require additional values. These values are provided default values after generation, change them to the desired values.

| Variable | Description | Value |
| -------------------- | -------------------------------------------- | ------------------------------------------------------------------- |
| BCRYPT_SALT | the string used for hashing | [random-string] |
| COMPOSE_PROJECT_NAME | the identifier of the service plus prefix | amp_[service-identifier] |
| PORT | the port on which to run the server | 3000 |
| DB_URL | the connection url for the database | [db-provider]://[username]:[password]@localhost:[db-port]/[db-name] |
| DB_PORT | the port used by the database instance | [db-provider-port] |
| DB_USER | the username used to connect to the database | [username] |
| DB_PASSWORD | the password used to connect to the database | [password] |
| DB_NAME | the name of the database | [service-name] / [project-name] |
| JWT_SECRET_KEY | the secret used to sign the json-web token | [secret] |
| JWT_EXPIRATION | the expiration time for the json-web token | 2d |

> **Note**
> Amplication generates default values and stores them under the .env file. It is advised to use some form of secrets manager/vault solution when using in production.

## Step 2.1: Scripts - pre-requisites

After configuration of the server the next step would be to run the application. Before running the server side of the component, make sure that the different pre-requisites are met - i.e., node.js [^16.x], npm, docker. After the setup of the pre-requisites the server component can be started.

```sh
# installation of the dependencies
$ npm install
```
```sh
# generate the prisma client
$ npm run prisma:generate
```
```sh
# start the database where the server component will connect to
$ npm run docker:db
```
```sh
# initialize the database
$ npm run db:init
```

## Step 2.2: Scripts - local development

```shell
# start the server component
$ npm run install
```

## Step 2.2: Scripts - container based development

```shell
# start the server component as a docker container
$ npm run compose:up
```
14 changes: 5 additions & 9 deletions packages/arcade/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
BCRYPT_SALT: ${BCRYPT_SALT}
JWT_SECRET_KEY: ${JWT_SECRET_KEY}
JWT_EXPIRATION: ${JWT_EXPIRATION}
DB_URL: postgres://${DB_USER}:${DB_PASSWORD}@db:5433
DB_URL: postgres://${DB_USER}:${DB_PASSWORD}@db:5432/${DB_NAME}
depends_on:
- migrate
migrate:
Expand All @@ -23,7 +23,7 @@ services:
working_dir: /app/server
environment:
BCRYPT_SALT: ${BCRYPT_SALT}
DB_URL: postgres://${DB_USER}:${DB_PASSWORD}@db:5432
DB_URL: postgres://${DB_USER}:${DB_PASSWORD}@db:5432/${DB_NAME}
depends_on:
db:
condition: service_healthy
Expand Down Expand Up @@ -61,17 +61,13 @@ services:
environment:
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: ${DB_NAME}
volumes:
- postgres:/var/lib/postgresql/data
healthcheck:
test:
- CMD
- pg_isready
- -q
- -d
- ${DB_DB_NAME}
- -U
- ${DB_USER}
- CMD-SHELL
- pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}
timeout: 45s
interval: 10s
retries: 10
Expand Down
22 changes: 12 additions & 10 deletions packages/arcade/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
"@nestjs/config": "1.1.5",
"@nestjs/core": "8.4.7",
"@nestjs/graphql": "9.1.2",
"@nestjs/jwt": "8.0.0",
"@nestjs/passport": "8.2.2",
"@nestjs/platform-express": "8.4.7",
"@nestjs/serve-static": "2.2.2",
"@nestjs/swagger": "5.1.5",
Expand All @@ -39,14 +37,17 @@
"nest-morgan": "1.0.1",
"nestjs-prisma": "0.19.0",
"npm-run-all": "4.1.5",
"passport": "0.6.0",
"passport-http": "0.3.0",
"passport-jwt": "4.0.0",
"reflect-metadata": "0.1.13",
"swagger-ui-express": "4.3.0",
"ts-node": "9.1.1",
"ts-node": "10.9.1",
"validator": "^13.9.0",
"@nestjs/microservices": "8.2.3",
"kafkajs": "2.2.0"
"kafkajs": "2.2.0",
"@nestjs/jwt": "^10.0.2",
"@nestjs/passport": "^9.0.0",
"passport": "0.6.0",
"passport-http": "0.3.0",
"passport-jwt": "4.0.1"
},
"devDependencies": {
"@nestjs/cli": "8.2.5",
Expand All @@ -56,16 +57,17 @@
"@types/graphql-type-json": "0.3.2",
"@types/jest": "26.0.19",
"@types/normalize-path": "3.0.0",
"@types/passport-http": "0.3.9",
"@types/passport-jwt": "3.0.6",
"@types/supertest": "2.0.11",
"@types/validator": "^13.7.15",
"jest": "27.0.6",
"jest-mock-extended": "^2.0.4",
"prisma": "4.6.1",
"supertest": "4.0.2",
"ts-jest": "27.0.3",
"type-fest": "0.11.0",
"typescript": "4.2.3"
"typescript": "4.2.3",
"@types/passport-http": "0.3.9",
"@types/passport-jwt": "3.0.8"
},
"jest": {
"preset": "ts-jest",
Expand Down
11 changes: 8 additions & 3 deletions packages/arcade/scripts/seed.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as dotenv from "dotenv";
import { PrismaClient } from "@prisma/client";
import { customSeed } from "./customSeed";
import { Salt, parseSalt } from "../src/auth/password.service";
import { hash } from "bcrypt";
import { customSeed } from "./customSeed";

if (require.main === module) {
dotenv.config();
Expand All @@ -12,7 +12,6 @@ if (require.main === module) {
if (!BCRYPT_SALT) {
throw new Error("BCRYPT_SALT environment variable must be defined");
}

const salt = parseSalt(BCRYPT_SALT);

seed(salt).catch((error) => {
Expand All @@ -25,16 +24,22 @@ async function seed(bcryptSalt: Salt) {
console.info("Seeding database...");

const client = new PrismaClient();

const data = {
username: "admin",
password: await hash("admin", bcryptSalt),
roles: ["user"],
};

await client.user.upsert({
where: { username: data.username },
where: {
username: data.username,
},

update: {},
create: data,
});

void client.$disconnect();

console.info("Seeding database with custom seed...");
Expand Down
12 changes: 7 additions & 5 deletions packages/arcade/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,29 @@ import { MorganInterceptor, MorganModule } from "nest-morgan";
import { UserModule } from "./user/user.module";
import { GameModule } from "./game/game.module";
import { SessionModule } from "./session/session.module";
import { ACLModule } from "./auth/acl.module";
import { AuthModule } from "./auth/auth.module";
import { HealthModule } from "./health/health.module";
import { PrismaModule } from "./prisma/prisma.module";
import { SecretsManagerModule } from "./providers/secrets/secretsManager.module";
import { KafkaModule } from "./kafka/kafka.module";
import { ConfigModule, ConfigService } from "@nestjs/config";
import { ServeStaticModule } from "@nestjs/serve-static";
import { ServeStaticOptionsService } from "./serveStaticOptions.service";
import { GraphQLModule } from "@nestjs/graphql";

import { ACLModule } from "./auth/acl.module";
import { AuthModule } from "./auth/auth.module";

@Module({
controllers: [],
imports: [
ACLModule,
AuthModule,
UserModule,
GameModule,
SessionModule,
ACLModule,
AuthModule,
HealthModule,
PrismaModule,
SecretsManagerModule,
KafkaModule,
MorganModule,
ConfigModule.forRoot({ isGlobal: true }),
ServeStaticModule.forRootAsync({
Expand Down
2 changes: 1 addition & 1 deletion packages/arcade/src/auth/UserInfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Field, ObjectType } from "@nestjs/graphql";
import { User } from "../user/base/user";
import { User } from "../user/base/User";

@ObjectType()
export class UserInfo implements Partial<User> {
Expand Down
Loading