Switched to NestJS
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -65,3 +65,4 @@ node_modules
|
|||||||
dist
|
dist
|
||||||
.graphqlrc.yml
|
.graphqlrc.yml
|
||||||
codegen.yml
|
codegen.yml
|
||||||
|
backend/src/config/kc.config.json
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
{
|
|
||||||
"directory": [
|
|
||||||
"./src/controllers/rest",
|
|
||||||
"./src/datasources",
|
|
||||||
"./src/resolvers"
|
|
||||||
],
|
|
||||||
"exclude": [
|
|
||||||
"__mock__",
|
|
||||||
"__mocks__",
|
|
||||||
".spec.ts"
|
|
||||||
],
|
|
||||||
"delete": true
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
node_modules
|
|
||||||
Dockerfile
|
|
||||||
.env.local
|
|
||||||
.env.development
|
|
||||||
25
backend/.eslintrc.js
Normal file
25
backend/.eslintrc.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
module.exports = {
|
||||||
|
parser: '@typescript-eslint/parser',
|
||||||
|
parserOptions: {
|
||||||
|
project: 'tsconfig.json',
|
||||||
|
tsconfigRootDir : __dirname,
|
||||||
|
sourceType: 'module',
|
||||||
|
},
|
||||||
|
plugins: ['@typescript-eslint/eslint-plugin'],
|
||||||
|
extends: [
|
||||||
|
'plugin:@typescript-eslint/recommended',
|
||||||
|
'plugin:prettier/recommended',
|
||||||
|
],
|
||||||
|
root: true,
|
||||||
|
env: {
|
||||||
|
node: true,
|
||||||
|
jest: true,
|
||||||
|
},
|
||||||
|
ignorePatterns: ['.eslintrc.js'],
|
||||||
|
rules: {
|
||||||
|
'@typescript-eslint/interface-name-prefix': 'off',
|
||||||
|
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||||
|
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||||
|
'@typescript-eslint/no-explicit-any': 'off',
|
||||||
|
},
|
||||||
|
};
|
||||||
74
backend/.gitignore
vendored
74
backend/.gitignore
vendored
@@ -1,57 +1,35 @@
|
|||||||
### Node template
|
# compiled output
|
||||||
.DS_Store
|
/dist
|
||||||
|
/node_modules
|
||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
logs
|
logs
|
||||||
*.log
|
*.log
|
||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
# Runtime data
|
# OS
|
||||||
pids
|
.DS_Store
|
||||||
*.pid
|
|
||||||
*.seed
|
|
||||||
|
|
||||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
# Tests
|
||||||
lib-cov
|
/coverage
|
||||||
|
|
||||||
# Coverage directory used by tools like istanbul
|
|
||||||
coverage
|
|
||||||
|
|
||||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
|
||||||
.grunt
|
|
||||||
|
|
||||||
# node-waf configuration
|
|
||||||
.lock-wscript
|
|
||||||
|
|
||||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
|
||||||
build/Release
|
|
||||||
|
|
||||||
# Dependency directory
|
|
||||||
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
|
|
||||||
node_modules
|
|
||||||
.npmrc
|
|
||||||
*.log
|
|
||||||
|
|
||||||
# Typings
|
|
||||||
typings/
|
|
||||||
|
|
||||||
# Typescript
|
|
||||||
src/**/*.js
|
|
||||||
src/**/*.js.map
|
|
||||||
test/**/*.js
|
|
||||||
test/**/*.js.map
|
|
||||||
|
|
||||||
# Test
|
|
||||||
/.tmp
|
|
||||||
/.nyc_output
|
/.nyc_output
|
||||||
|
|
||||||
# IDE
|
# IDEs and editors
|
||||||
.vscode
|
/.idea
|
||||||
.idea
|
.project
|
||||||
|
.classpath
|
||||||
|
.c9/
|
||||||
|
*.launch
|
||||||
|
.settings/
|
||||||
|
*.sublime-workspace
|
||||||
|
|
||||||
# Project
|
# IDE - VSCode
|
||||||
/public
|
.vscode/*
|
||||||
/dist
|
!.vscode/settings.json
|
||||||
|
!.vscode/tasks.json
|
||||||
#env
|
!.vscode/launch.json
|
||||||
.env.local
|
!.vscode/extensions.json
|
||||||
.env.development
|
|
||||||
4
backend/.prettierrc
Normal file
4
backend/.prettierrc
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"singleQuote": true,
|
||||||
|
"trailingComma": "all"
|
||||||
|
}
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
###############################################################################
|
|
||||||
###############################################################################
|
|
||||||
## _______ _____ ______ _____ ##
|
|
||||||
## |__ __/ ____| ____| __ \ ##
|
|
||||||
## | | | (___ | |__ | | | | ##
|
|
||||||
## | | \___ \| __| | | | | ##
|
|
||||||
## | | ____) | |____| |__| | ##
|
|
||||||
## |_| |_____/|______|_____/ ##
|
|
||||||
## ##
|
|
||||||
## description : Dockerfile for TsED Application ##
|
|
||||||
## author : TsED team ##
|
|
||||||
## date : 2022-03-05 ##
|
|
||||||
## version : 2.0 ##
|
|
||||||
## ##
|
|
||||||
###############################################################################
|
|
||||||
###############################################################################
|
|
||||||
ARG NODE_VERSION=16.13.1
|
|
||||||
|
|
||||||
FROM node:${NODE_VERSION}-alpine as build
|
|
||||||
WORKDIR /opt
|
|
||||||
|
|
||||||
COPY package.json yarn.lock tsconfig.json tsconfig.compile.json .barrelsby.json ./
|
|
||||||
|
|
||||||
RUN yarn install --pure-lockfile
|
|
||||||
|
|
||||||
COPY ./src ./src
|
|
||||||
|
|
||||||
RUN yarn build
|
|
||||||
|
|
||||||
FROM node:${NODE_VERSION}-alpine as runtime
|
|
||||||
ENV WORKDIR /opt
|
|
||||||
WORKDIR $WORKDIR
|
|
||||||
|
|
||||||
RUN apk update && apk add build-base git curl
|
|
||||||
RUN npm install -g pm2
|
|
||||||
|
|
||||||
COPY --from=build /opt .
|
|
||||||
|
|
||||||
RUN yarn install --pure-lockfile --production
|
|
||||||
COPY ./prisma ./prisma
|
|
||||||
COPY processes.config.js .
|
|
||||||
|
|
||||||
EXPOSE 8081
|
|
||||||
ENV PORT 8081
|
|
||||||
ENV NODE_ENV production
|
|
||||||
|
|
||||||
CMD ["pm2-runtime", "start", "processes.config.js", "--env", "production"]
|
|
||||||
@@ -1,67 +1,73 @@
|
|||||||
<p style="text-align: center" align="center">
|
<p align="center">
|
||||||
<a href="https://tsed.io" target="_blank"><img src="https://tsed.io/tsed-og.png" width="200" alt="Ts.ED logo"/></a>
|
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div align="center">
|
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
|
||||||
<h1>Ts.ED - backend</h1>
|
[circleci-url]: https://circleci.com/gh/nestjs/nest
|
||||||
<br />
|
|
||||||
<div align="center">
|
|
||||||
<a href="https://cli.tsed.io/">Website</a>
|
|
||||||
<span> • </span>
|
|
||||||
<a href="https://cli.tsed.io/getting-started.html">Getting started</a>
|
|
||||||
<span> • </span>
|
|
||||||
<a href="https://api.tsed.io/rest/slack/tsedio/tsed">Slack</a>
|
|
||||||
<span> • </span>
|
|
||||||
<a href="https://twitter.com/TsED_io">Twitter</a>
|
|
||||||
</div>
|
|
||||||
<hr />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
> An awesome project based on Ts.ED framework
|
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
|
||||||
|
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
|
||||||
|
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
|
||||||
|
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
|
||||||
|
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
|
||||||
|
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
|
||||||
|
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
|
||||||
|
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
|
||||||
|
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
|
||||||
|
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
|
||||||
|
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
|
||||||
|
</p>
|
||||||
|
<!--[](https://opencollective.com/nest#backer)
|
||||||
|
[](https://opencollective.com/nest#sponsor)-->
|
||||||
|
|
||||||
## Getting started
|
## Description
|
||||||
|
|
||||||
> **Important!** Ts.ED requires Node >= 14, Express >= 4 and TypeScript >= 4.
|
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
|
||||||
|
|
||||||
```batch
|
## Installation
|
||||||
# install dependencies
|
|
||||||
$ install
|
|
||||||
|
|
||||||
# serve
|
```bash
|
||||||
$ start
|
$ npm install
|
||||||
|
|
||||||
# build for production
|
|
||||||
$ build
|
|
||||||
$ start:prod
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Docker
|
## Running the app
|
||||||
|
|
||||||
```
|
```bash
|
||||||
# build docker image
|
# development
|
||||||
docker compose build
|
$ npm run start
|
||||||
|
|
||||||
# start docker image
|
# watch mode
|
||||||
docker compose up
|
$ npm run start:dev
|
||||||
|
|
||||||
|
# production mode
|
||||||
|
$ npm run start:prod
|
||||||
```
|
```
|
||||||
|
|
||||||
## Barrelsby
|
## Test
|
||||||
|
|
||||||
This project uses [barrelsby](https://www.npmjs.com/package/barrelsby) to generate index files to import the controllers.
|
```bash
|
||||||
|
# unit tests
|
||||||
|
$ npm run test
|
||||||
|
|
||||||
Edit `.barreslby.json` to customize it:
|
# e2e tests
|
||||||
|
$ npm run test:e2e
|
||||||
|
|
||||||
```json
|
# test coverage
|
||||||
{
|
$ npm run test:cov
|
||||||
"directory": [
|
|
||||||
"./src/controllers/rest",
|
|
||||||
"./src/controllers/pages"
|
|
||||||
],
|
|
||||||
"exclude": [
|
|
||||||
"__mock__",
|
|
||||||
"__mocks__",
|
|
||||||
".spec.ts"
|
|
||||||
],
|
|
||||||
"delete": true
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Support
|
||||||
|
|
||||||
|
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
|
||||||
|
|
||||||
|
## Stay in touch
|
||||||
|
|
||||||
|
- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
|
||||||
|
- Website - [https://nestjs.com](https://nestjs.com/)
|
||||||
|
- Twitter - [@nestframework](https://twitter.com/nestframework)
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Nest is [MIT licensed](LICENSE).
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
version: '3.5'
|
|
||||||
services:
|
|
||||||
server:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: ./Dockerfile
|
|
||||||
args:
|
|
||||||
- http_proxy
|
|
||||||
- https_proxy
|
|
||||||
- no_proxy
|
|
||||||
image: backend/server:latest
|
|
||||||
ports:
|
|
||||||
- "8081:8081"
|
|
||||||
|
|
||||||
5
backend/nest-cli.json
Normal file
5
backend/nest-cli.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/nest-cli",
|
||||||
|
"collection": "@nestjs/schematics",
|
||||||
|
"sourceRoot": "src"
|
||||||
|
}
|
||||||
@@ -1,80 +1,71 @@
|
|||||||
{
|
{
|
||||||
"name": "backend",
|
"name": "backend",
|
||||||
"version": "1.0.0",
|
"version": "0.0.1",
|
||||||
"description": "",
|
"description": "",
|
||||||
|
"author": "",
|
||||||
|
"private": true,
|
||||||
|
"license": "UNLICENSED",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "yarn run barrels && tsc --project tsconfig.compile.json",
|
"prebuild": "rimraf dist",
|
||||||
"barrels": "barrelsby --config .barrelsby.json",
|
"build": "nest build",
|
||||||
"start": "yarn run barrels && tsnd --inspect --ignore-watch node_modules --respawn --transpile-only -r tsconfig-paths/register src/index.ts",
|
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||||
"start:prod": "cross-env NODE_ENV=production node dist/index.js",
|
"start": "nest start",
|
||||||
"prisma:migrate": "npx prisma migrate dev --name init",
|
"start:dev": "nest start --watch",
|
||||||
"prisma:generate": "npx prisma generate"
|
"start:debug": "nest start --debug --watch",
|
||||||
|
"start:prod": "node dist/main",
|
||||||
|
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||||
|
"test": "jest",
|
||||||
|
"test:watch": "jest --watch",
|
||||||
|
"test:cov": "jest --coverage",
|
||||||
|
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||||
|
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@prisma/client": "^4.3.1",
|
"@nestjs/common": "^9.0.0",
|
||||||
"@tsed/ajv": "^6.129.0",
|
"@nestjs/core": "^9.0.0",
|
||||||
"@tsed/common": "^6.129.0",
|
"@nestjs/platform-express": "^9.0.0",
|
||||||
"@tsed/core": "^6.129.0",
|
"reflect-metadata": "^0.1.13",
|
||||||
"@tsed/di": "^6.129.0",
|
"rimraf": "^3.0.2",
|
||||||
"@tsed/engines": "^6.129.0",
|
"rxjs": "^7.2.0"
|
||||||
"@tsed/exceptions": "^6.129.0",
|
|
||||||
"@tsed/json-mapper": "^6.129.0",
|
|
||||||
"@tsed/logger": "^6.2.2",
|
|
||||||
"@tsed/logger-file": "^6.2.2",
|
|
||||||
"@tsed/platform-cache": "^6.129.0",
|
|
||||||
"@tsed/platform-exceptions": "^6.129.0",
|
|
||||||
"@tsed/platform-express": "^6.129.0",
|
|
||||||
"@tsed/platform-log-middleware": "^6.129.0",
|
|
||||||
"@tsed/platform-middlewares": "^6.129.0",
|
|
||||||
"@tsed/platform-params": "^6.129.0",
|
|
||||||
"@tsed/platform-response-filter": "^6.129.0",
|
|
||||||
"@tsed/platform-views": "^6.129.0",
|
|
||||||
"@tsed/prisma": "^6.129.0",
|
|
||||||
"@tsed/schema": "^6.129.0",
|
|
||||||
"@tsed/socketio": "^6.129.0",
|
|
||||||
"@tsed/typegraphql": "^6.129.0",
|
|
||||||
"ajv": "^8.11.0",
|
|
||||||
"apollo-datasource": "^3.3.1",
|
|
||||||
"apollo-datasource-rest": "^3.5.1",
|
|
||||||
"apollo-server-core": "^3.6.2",
|
|
||||||
"apollo-server-express": "2.25.2",
|
|
||||||
"barrelsby": "^2.4.0",
|
|
||||||
"body-parser": "^1.20.0",
|
|
||||||
"class-validator": "^0.13.2",
|
|
||||||
"compression": "^1.7.4",
|
|
||||||
"cookie-parser": "^1.4.6",
|
|
||||||
"cors": "^2.8.5",
|
|
||||||
"cross-env": "^7.0.3",
|
|
||||||
"dotenv": "^16.0.2",
|
|
||||||
"dotenv-expand": "^9.0.0",
|
|
||||||
"dotenv-flow": "^3.2.0",
|
|
||||||
"express": "^4.18.1",
|
|
||||||
"graphql": "^15.7.2",
|
|
||||||
"method-override": "^3.0.0",
|
|
||||||
"socket.io": "^4.5.2",
|
|
||||||
"type-graphql": "^1.1.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tsed/cli-plugin-prisma": "3.26.0",
|
"@nestjs/cli": "^9.0.0",
|
||||||
"@tsed/cli-plugin-typegraphql": "3.26.0",
|
"@nestjs/schematics": "^9.0.0",
|
||||||
"@types/compression": "^1.7.2",
|
"@nestjs/testing": "^9.0.0",
|
||||||
"@types/cookie-parser": "^1.4.3",
|
|
||||||
"@types/cors": "^2.8.12",
|
|
||||||
"@types/express": "^4.17.13",
|
"@types/express": "^4.17.13",
|
||||||
"@types/method-override": "^0.0.32",
|
"@types/jest": "28.1.8",
|
||||||
"@types/multer": "^1.4.7",
|
"@types/node": "^16.0.0",
|
||||||
"@types/node": "^18.7.14",
|
"@types/supertest": "^2.0.11",
|
||||||
"@types/validator": "^13.7.6",
|
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
||||||
"apollo-server-testing": "^2.25.3",
|
"@typescript-eslint/parser": "^5.0.0",
|
||||||
"ts-node": "^10.9.1",
|
"eslint": "^8.0.1",
|
||||||
"ts-node-dev": "^2.0.0",
|
"eslint-config-prettier": "^8.3.0",
|
||||||
"tsconfig-paths": "^4.1.0",
|
"eslint-plugin-prettier": "^4.0.0",
|
||||||
"tslib": "^2.4.0",
|
"jest": "28.1.3",
|
||||||
"typescript": "^4.8.2"
|
"prettier": "^2.3.2",
|
||||||
|
"source-map-support": "^0.5.20",
|
||||||
|
"supertest": "^6.1.3",
|
||||||
|
"ts-jest": "28.0.8",
|
||||||
|
"ts-loader": "^9.2.3",
|
||||||
|
"ts-node": "^10.0.0",
|
||||||
|
"tsconfig-paths": "4.1.0",
|
||||||
|
"typescript": "~4.7.4"
|
||||||
},
|
},
|
||||||
"tsed": {
|
"jest": {
|
||||||
"packageManager": "yarn",
|
"moduleFileExtensions": [
|
||||||
"convention": "default",
|
"js",
|
||||||
"architecture": "default"
|
"json",
|
||||||
|
"ts"
|
||||||
|
],
|
||||||
|
"rootDir": "src",
|
||||||
|
"testRegex": ".*\\.spec\\.ts$",
|
||||||
|
"transform": {
|
||||||
|
"^.+\\.(t|j)s$": "ts-jest"
|
||||||
|
},
|
||||||
|
"collectCoverageFrom": [
|
||||||
|
"**/*.(t|j)s"
|
||||||
|
],
|
||||||
|
"coverageDirectory": "../coverage",
|
||||||
|
"testEnvironment": "node"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
// This is your Prisma schema file,
|
|
||||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
|
||||||
|
|
||||||
generator client {
|
|
||||||
provider = "prisma-client-js"
|
|
||||||
}
|
|
||||||
|
|
||||||
datasource db {
|
|
||||||
provider = "postgresql"
|
|
||||||
url = env("DATABASE_URL")
|
|
||||||
}
|
|
||||||
|
|
||||||
generator tsed {
|
|
||||||
provider = "tsed-prisma"
|
|
||||||
}
|
|
||||||
|
|
||||||
model User {
|
|
||||||
id Int @default(autoincrement()) @id
|
|
||||||
email String @unique
|
|
||||||
name String?
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
const path = require('path')
|
|
||||||
const defaultLogFile = path.join(__dirname, '/logs/project-server.log')
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
'apps': [
|
|
||||||
{
|
|
||||||
name: "api",
|
|
||||||
'script': `${process.env.WORKDIR}/dist/index.js`,
|
|
||||||
'cwd': process.env.WORKDIR,
|
|
||||||
node_args: process.env.NODE_ARGS || "--max_old_space_size=1800",
|
|
||||||
exec_mode: "cluster",
|
|
||||||
instances: process.env.NODE_ENV === "test" ? 1 : process.env.NB_INSTANCES || 2,
|
|
||||||
autorestart: true,
|
|
||||||
max_memory_restart: process.env.MAX_MEMORY_RESTART || "750M",
|
|
||||||
'out_file': defaultLogFile,
|
|
||||||
'error_file': defaultLogFile,
|
|
||||||
'merge_logs': true,
|
|
||||||
'kill_timeout': 30000,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
import {join} from "path";
|
|
||||||
import {Configuration, Inject} from "@tsed/di";
|
|
||||||
import {PlatformApplication} from "@tsed/common";
|
|
||||||
import "@tsed/platform-express"; // /!\ keep this import
|
|
||||||
import bodyParser from "body-parser";
|
|
||||||
import compress from "compression";
|
|
||||||
import cookieParser from "cookie-parser";
|
|
||||||
import methodOverride from "method-override";
|
|
||||||
import cors from "cors";
|
|
||||||
import "@tsed/ajv";
|
|
||||||
import "@tsed/typegraphql";
|
|
||||||
import "./datasources/index";
|
|
||||||
import "./resolvers/index";
|
|
||||||
import {config} from "./config/index";
|
|
||||||
import * as rest from "./controllers/rest/index";
|
|
||||||
|
|
||||||
@Configuration({
|
|
||||||
...config,
|
|
||||||
acceptMimes: ["application/json"],
|
|
||||||
httpPort: process.env.PORT || 8083,
|
|
||||||
httpsPort: false, // CHANGE
|
|
||||||
componentsScan: false,
|
|
||||||
mount: {
|
|
||||||
"/rest": [
|
|
||||||
...Object.values(rest)
|
|
||||||
]
|
|
||||||
},
|
|
||||||
middlewares: [
|
|
||||||
cors(),
|
|
||||||
cookieParser(),
|
|
||||||
compress({}),
|
|
||||||
methodOverride(),
|
|
||||||
bodyParser.json(),
|
|
||||||
bodyParser.urlencoded({
|
|
||||||
extended: true
|
|
||||||
})
|
|
||||||
],
|
|
||||||
views: {
|
|
||||||
root: join(process.cwd(), "../views"),
|
|
||||||
extensions: {
|
|
||||||
ejs: "ejs"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
exclude: [
|
|
||||||
"**/*.spec.ts"
|
|
||||||
]
|
|
||||||
})
|
|
||||||
export class Server {
|
|
||||||
@Inject()
|
|
||||||
protected app: PlatformApplication;
|
|
||||||
|
|
||||||
@Configuration()
|
|
||||||
protected settings: Configuration;
|
|
||||||
}
|
|
||||||
22
backend/src/app.controller.spec.ts
Normal file
22
backend/src/app.controller.spec.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { AppController } from './app.controller';
|
||||||
|
import { AppService } from './app.service';
|
||||||
|
|
||||||
|
describe('AppController', () => {
|
||||||
|
let appController: AppController;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const app: TestingModule = await Test.createTestingModule({
|
||||||
|
controllers: [AppController],
|
||||||
|
providers: [AppService],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
appController = app.get<AppController>(AppController);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('root', () => {
|
||||||
|
it('should return "Hello World!"', () => {
|
||||||
|
expect(appController.getHello()).toBe('Hello World!');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
12
backend/src/app.controller.ts
Normal file
12
backend/src/app.controller.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { Controller, Get } from '@nestjs/common';
|
||||||
|
import { AppService } from './app.service';
|
||||||
|
|
||||||
|
@Controller()
|
||||||
|
export class AppController {
|
||||||
|
constructor(private readonly appService: AppService) {}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
getHello(): string {
|
||||||
|
return this.appService.getHello();
|
||||||
|
}
|
||||||
|
}
|
||||||
10
backend/src/app.module.ts
Normal file
10
backend/src/app.module.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { AppController } from './app.controller';
|
||||||
|
import { AppService } from './app.service';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [],
|
||||||
|
controllers: [AppController],
|
||||||
|
providers: [AppService],
|
||||||
|
})
|
||||||
|
export class AppModule {}
|
||||||
8
backend/src/app.service.ts
Normal file
8
backend/src/app.service.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class AppService {
|
||||||
|
getHello(): string {
|
||||||
|
return 'Hello World!';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
import dotenv from "dotenv"
|
|
||||||
|
|
||||||
export const envs = {
|
|
||||||
...process.env,
|
|
||||||
...dotenv.config().parsed
|
|
||||||
};
|
|
||||||
export const isProduction = process.env.NODE_ENV === "production";
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
import {readFileSync} from "fs";
|
|
||||||
import {envs} from "./envs/index";
|
|
||||||
import loggerConfig from "./logger/index";
|
|
||||||
const pkg = JSON.parse(readFileSync("./package.json", {encoding: "utf8"}));
|
|
||||||
|
|
||||||
export const config: Partial<TsED.Configuration> = {
|
|
||||||
version: pkg.version,
|
|
||||||
envs,
|
|
||||||
logger: loggerConfig,
|
|
||||||
graphql: {
|
|
||||||
default: {
|
|
||||||
path: "/graphql",
|
|
||||||
buildSchemaOptions: {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// additional shared configuration
|
|
||||||
};
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
import {$log, PlatformLoggerSettings} from "@tsed/common";
|
|
||||||
import {isProduction} from "../envs/index";
|
|
||||||
|
|
||||||
if (isProduction) {
|
|
||||||
$log.appenders.set("stdout", {
|
|
||||||
type: "stdout",
|
|
||||||
levels: ["info", "debug"],
|
|
||||||
layout: {
|
|
||||||
type: "json"
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$log.appenders.set("stderr", {
|
|
||||||
levels: ["trace", "fatal", "error", "warn"],
|
|
||||||
type: "stderr",
|
|
||||||
layout: {
|
|
||||||
type: "json"
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export default <PlatformLoggerSettings> {
|
|
||||||
disableRoutesSummary: isProduction
|
|
||||||
};
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
import {Controller} from "@tsed/di";
|
|
||||||
import {Get} from "@tsed/schema";
|
|
||||||
|
|
||||||
@Controller("/hello-world")
|
|
||||||
export class HelloWorldController {
|
|
||||||
@Get("/")
|
|
||||||
get() {
|
|
||||||
return "hello";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
/**
|
|
||||||
* @file Automatically generated by barrelsby.
|
|
||||||
*/
|
|
||||||
|
|
||||||
export * from "./HelloWorldController";
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
import {DataSourceService} from "@tsed/typegraphql";
|
|
||||||
import {RESTDataSource} from "apollo-datasource-rest";
|
|
||||||
|
|
||||||
@DataSourceService()
|
|
||||||
export class MyDataSource extends RESTDataSource {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
this.baseURL = "http://localhost:8001";
|
|
||||||
}
|
|
||||||
|
|
||||||
willSendRequest(request: any) {
|
|
||||||
request.headers.set("Authorization", this.context.token);
|
|
||||||
}
|
|
||||||
|
|
||||||
getMyData(id: string) {
|
|
||||||
return this.get(`/rest/calendars/${id}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
/**
|
|
||||||
* @file Automatically generated by barrelsby.
|
|
||||||
*/
|
|
||||||
|
|
||||||
export * from "./MyDataSource";
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
import {$log} from "@tsed/common";
|
|
||||||
import { PlatformExpress } from "@tsed/platform-express";
|
|
||||||
import {Server} from "./Server";
|
|
||||||
|
|
||||||
async function bootstrap() {
|
|
||||||
try {
|
|
||||||
const platform = await PlatformExpress.bootstrap(Server);
|
|
||||||
await platform.listen();
|
|
||||||
|
|
||||||
process.on("SIGINT", () => {
|
|
||||||
platform.stop();
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
$log.error({event: "SERVER_BOOTSTRAP_ERROR", message: error.message, stack: error.stack});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bootstrap();
|
|
||||||
8
backend/src/main.ts
Normal file
8
backend/src/main.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { NestFactory } from '@nestjs/core';
|
||||||
|
import { AppModule } from './app.module';
|
||||||
|
|
||||||
|
async function bootstrap() {
|
||||||
|
const app = await NestFactory.create(AppModule);
|
||||||
|
await app.listen(3000);
|
||||||
|
}
|
||||||
|
bootstrap();
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
/**
|
|
||||||
* @file Automatically generated by barrelsby.
|
|
||||||
*/
|
|
||||||
|
|
||||||
export * from "./recipes/Recipe";
|
|
||||||
export * from "./recipes/RecipeNotFoundError";
|
|
||||||
export * from "./recipes/RecipeResolver";
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
import {Field, ID, ObjectType} from "type-graphql";
|
|
||||||
|
|
||||||
@ObjectType({description: "Object representing cooking recipe"})
|
|
||||||
export class Recipe {
|
|
||||||
@Field((type) => ID)
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
@Field()
|
|
||||||
title: string;
|
|
||||||
|
|
||||||
@Field({nullable: true})
|
|
||||||
description?: string;
|
|
||||||
|
|
||||||
@Field()
|
|
||||||
creationDate: Date;
|
|
||||||
|
|
||||||
@Field((type) => [String])
|
|
||||||
ingredients: string[];
|
|
||||||
|
|
||||||
constructor(options: Partial<Recipe> = {}) {
|
|
||||||
options.id && (this.id = options.id);
|
|
||||||
options.title && (this.title = options.title);
|
|
||||||
options.description && (this.description = options.description);
|
|
||||||
options.creationDate && (this.creationDate = options.creationDate);
|
|
||||||
options.ingredients && (this.ingredients = options.ingredients);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
import {NotFound} from "@tsed/exceptions";
|
|
||||||
|
|
||||||
export class RecipeNotFoundError extends NotFound {
|
|
||||||
constructor(private id: string) {
|
|
||||||
super("Recipe not found");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
import {ResolverService} from "@tsed/typegraphql";
|
|
||||||
import {Arg, Query} from "type-graphql";
|
|
||||||
import {RecipeService} from "../../services/RecipeService";
|
|
||||||
import {Recipe} from "./Recipe";
|
|
||||||
import {RecipeNotFoundError} from "./RecipeNotFoundError";
|
|
||||||
|
|
||||||
@ResolverService(Recipe)
|
|
||||||
export class RecipeResolver {
|
|
||||||
constructor(private recipeService: RecipeService) {}
|
|
||||||
|
|
||||||
@Query((returns) => Recipe)
|
|
||||||
async recipe(@Arg("id") id: string) {
|
|
||||||
const recipe = await this.recipeService.findById(id);
|
|
||||||
|
|
||||||
if (recipe === undefined) {
|
|
||||||
throw new RecipeNotFoundError(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return recipe;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Query((returns) => [Recipe], {description: "Get all the recipes from around the world "})
|
|
||||||
async recipes(): Promise<Recipe[]> {
|
|
||||||
return this.recipeService.findAll({});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
import {Injectable} from "@tsed/di";
|
|
||||||
import {Recipe} from "../resolvers";
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class RecipeService {
|
|
||||||
async findById(id: string) {
|
|
||||||
return new Recipe({id})
|
|
||||||
}
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
async findAll(query: any) {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
24
backend/test/app.e2e-spec.ts
Normal file
24
backend/test/app.e2e-spec.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { INestApplication } from '@nestjs/common';
|
||||||
|
import * as request from 'supertest';
|
||||||
|
import { AppModule } from './../src/app.module';
|
||||||
|
|
||||||
|
describe('AppController (e2e)', () => {
|
||||||
|
let app: INestApplication;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const moduleFixture: TestingModule = await Test.createTestingModule({
|
||||||
|
imports: [AppModule],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
app = moduleFixture.createNestApplication();
|
||||||
|
await app.init();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('/ (GET)', () => {
|
||||||
|
return request(app.getHttpServer())
|
||||||
|
.get('/')
|
||||||
|
.expect(200)
|
||||||
|
.expect('Hello World!');
|
||||||
|
});
|
||||||
|
});
|
||||||
9
backend/test/jest-e2e.json
Normal file
9
backend/test/jest-e2e.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"moduleFileExtensions": ["js", "json", "ts"],
|
||||||
|
"rootDir": ".",
|
||||||
|
"testEnvironment": "node",
|
||||||
|
"testRegex": ".e2e-spec.ts$",
|
||||||
|
"transform": {
|
||||||
|
"^.+\\.(t|j)s$": "ts-jest"
|
||||||
|
}
|
||||||
|
}
|
||||||
4
backend/tsconfig.build.json
Normal file
4
backend/tsconfig.build.json
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
|
||||||
|
}
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "./tsconfig.json",
|
|
||||||
"compilerOptions": {
|
|
||||||
"baseUrl": ".",
|
|
||||||
"outDir": "./dist",
|
|
||||||
"moduleResolution": "node",
|
|
||||||
"declaration": true,
|
|
||||||
"noResolve": false,
|
|
||||||
"preserveConstEnums": true,
|
|
||||||
"sourceMap": true,
|
|
||||||
"noEmit": false,
|
|
||||||
"emitDeclarationOnly": false,
|
|
||||||
"inlineSources": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +1,21 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"baseUrl": ".",
|
|
||||||
"sourceRoot": "src",
|
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"target": "esnext",
|
"declaration": true,
|
||||||
"sourceMap": true,
|
"removeComments": true,
|
||||||
"declaration": false,
|
|
||||||
"experimentalDecorators": true,
|
|
||||||
"emitDecoratorMetadata": true,
|
"emitDecoratorMetadata": true,
|
||||||
"moduleResolution": "node",
|
"experimentalDecorators": true,
|
||||||
"isolatedModules": false,
|
|
||||||
"suppressImplicitAnyIndexErrors": false,
|
|
||||||
"noImplicitAny": true,
|
|
||||||
"strictNullChecks": true,
|
|
||||||
"noUnusedLocals": false,
|
|
||||||
"noUnusedParameters": false,
|
|
||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
"importHelpers": true,
|
"target": "es2017",
|
||||||
"newLine": "LF",
|
"sourceMap": true,
|
||||||
"noEmit": true,
|
"outDir": "./dist",
|
||||||
"esModuleInterop": true,
|
"baseUrl": "./",
|
||||||
"resolveJsonModule": true,
|
"incremental": true,
|
||||||
"lib": [
|
"skipLibCheck": true,
|
||||||
"es7",
|
"strictNullChecks": false,
|
||||||
"dom",
|
"noImplicitAny": false,
|
||||||
"ESNext.AsyncIterable"
|
"strictBindCallApply": false,
|
||||||
],
|
"forceConsistentCasingInFileNames": false,
|
||||||
"typeRoots": [
|
"noFallthroughCasesInSwitch": false
|
||||||
"./node_modules/@types"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"include": [
|
|
||||||
"src"
|
|
||||||
],
|
|
||||||
"linterOptions": {
|
|
||||||
"exclude": []
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
5582
backend/yarn.lock
5582
backend/yarn.lock
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user