parent
							
								
									444a5b345a
								
							
						
					
					
						commit
						3355b9bf25
					
				@ -1,6 +0,0 @@
 | 
				
			|||||||
PORT=3005
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
DATABASE_URL=postgresql://postgres:postgres@localhost:5433/user-authentication
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
PUBLIC_KEY_PATH=tokens/jwt.key.pub
 | 
					 | 
				
			||||||
PRIVATE_KEY_PATH=tokens/jwt.key
 | 
					 | 
				
			||||||
@ -1,32 +0,0 @@
 | 
				
			|||||||
# syntax=docker/dockerfile:1
 | 
					 | 
				
			||||||
FROM node:18
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
WORKDIR /app
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
COPY --chown=node:node . .
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
RUN rm -f *.env *.env.*
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
RUN apt-get update -y && apt-get install -y dumb-init
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
RUN npm install
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
ENV NODE_ENV=production
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
RUN npm run prefullbuild && npm run prebuild && npm run build
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
RUN mkdir temp temp/.prisma temp/@prisma temp/prisma && cp -r ./node_modules/.prisma/* ./temp/.prisma/ && cp -r ./node_modules/@prisma/* ./temp/@prisma/ && cp -r  ./node_modules/prisma/* ./temp/prisma/
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
RUN rm -rdf node_modules
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
RUN npm install --production
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
RUN cp -r ./temp/* ./node_modules/ && rm -rdf temp
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
RUN ls | grep -v node_modules | grep -v dist | xargs rm -rfv
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
RUN cp -r ./dist/* ./ && rm -rdf dist
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
USER node
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
CMD ["dumb-init", "node", "./main.js"]
 | 
					 | 
				
			||||||
@ -1 +0,0 @@
 | 
				
			|||||||
migrations
 | 
					 | 
				
			||||||
@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					node_modules
 | 
				
			||||||
 | 
					# Keep environment variables out of version control
 | 
				
			||||||
 | 
					.env
 | 
				
			||||||
@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					export { PrismaClient as AuthClient } from '.prisma/auth-client';
 | 
				
			||||||
 | 
					export * from '.prisma/auth-client';
 | 
				
			||||||
@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					export class RecordNotFoundError extends Error {}
 | 
				
			||||||
@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					export class UniqueConstraintFailedError extends Error {}
 | 
				
			||||||
@ -0,0 +1,26 @@
 | 
				
			|||||||
 | 
					import {
 | 
				
			||||||
 | 
					  CallHandler,
 | 
				
			||||||
 | 
					  ConflictException,
 | 
				
			||||||
 | 
					  ExecutionContext,
 | 
				
			||||||
 | 
					  Injectable,
 | 
				
			||||||
 | 
					  NestInterceptor,
 | 
				
			||||||
 | 
					  NotFoundException,
 | 
				
			||||||
 | 
					} from '@nestjs/common';
 | 
				
			||||||
 | 
					import { catchError, Observable } from 'rxjs';
 | 
				
			||||||
 | 
					import { RecordNotFoundError } from '../error/record-not-found.error';
 | 
				
			||||||
 | 
					import { UniqueConstraintFailedError } from '../error/unique-constraint-failed.error';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Injectable()
 | 
				
			||||||
 | 
					export class PrismaErrorInterceptor implements NestInterceptor {
 | 
				
			||||||
 | 
					  intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
 | 
				
			||||||
 | 
					    return next.handle().pipe(
 | 
				
			||||||
 | 
					      catchError((err) => {
 | 
				
			||||||
 | 
					        if (err instanceof RecordNotFoundError)
 | 
				
			||||||
 | 
					          throw new NotFoundException(err.message);
 | 
				
			||||||
 | 
					        if (err instanceof UniqueConstraintFailedError)
 | 
				
			||||||
 | 
					          throw new ConflictException(err.message);
 | 
				
			||||||
 | 
					        throw err;
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					export { AuthClient } from './auth';
 | 
				
			||||||
					Loading…
					
					
				
		Reference in new issue