File tree Expand file tree Collapse file tree
examples_new/microservices/items Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2121 "@chronosrx/common" : " ^1.0.4" ,
2222 "axios" : " ^1.6.2" ,
2323 "cookie-parser" : " ^1.4.6" ,
24+ "cors" : " ^2.8.5" ,
2425 "dotenv" : " ^16.3.1" ,
2526 "express" : " ^4.18.2" ,
2627 "express-async-errors" : " ^3.1.1" ,
2930 },
3031 "devDependencies" : {
3132 "@types/cookie-parser" : " ^1.4.6" ,
33+ "@types/cors" : " ^2.8.17" ,
3234 "@types/express" : " ^4.17.21" ,
3335 "@types/jest" : " ^29.5.11" ,
3436 "@types/jsonwebtoken" : " ^9.0.5" ,
Original file line number Diff line number Diff line change @@ -2,13 +2,20 @@ import express from 'express';
22import 'express-async-errors' ;
33import dotenv from 'dotenv' ;
44dotenv . config ( ) ;
5+ import cors from 'cors'
56import { NotFoundError , errorHandler } from '@chronosrx/common' ;
67import itemsRouter from './routes/item-router' ;
78import eventRouter from './routes/event-router' ;
89import cookieParser from 'cookie-parser' ;
910
1011const app = express ( ) ;
1112
13+ app . use (
14+ cors ( {
15+ credentials : true ,
16+ origin : 'http://localhost:8080' ,
17+ } )
18+ ) ;
1219app . use ( express . json ( ) ) ;
1320app . use ( cookieParser ( ) ) ;
1421
Original file line number Diff line number Diff line change 11import { DbConnectionError } from '@chronosrx/common' ;
22import { app } from './app' ;
33import mongoose from 'mongoose' ;
4+ import { Item } from './models/items' ;
5+ import { User } from './models/users' ;
46
57const PORT = process . env . PORT || 3001 ;
68
@@ -11,6 +13,10 @@ const start = async () => {
1113 try {
1214 await mongoose . connect ( process . env . MONGO_URI , { } ) ;
1315 console . log ( '🍃 Connected to MongoDB' ) ;
16+
17+ // reset DB's
18+ await User . deleteMany ( ) ;
19+ await Item . deleteMany ( ) ;
1420 } catch ( err ) {
1521 throw new DbConnectionError ( ) ;
1622 }
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ const itemSchema = new mongoose.Schema(
2020 itemName : {
2121 type : String ,
2222 required : true ,
23+ unique : true ,
2324 } ,
2425 } ,
2526 {
You can’t perform that action at this time.
0 commit comments