diff --git a/README.md b/README.md index a7cb0d1..c00a285 100644 --- a/README.md +++ b/README.md @@ -2,16 +2,38 @@ An online storefront to showcase products. Users is able to browse an index of all products, see the specifics of a single product, and add products to an order that they can view in a cart page. +# Pre-requisite + +- Add a `.env` file in /Shelf folder with the following : + +``` +POSTGRES_HOST=127.0.0.1 +POSTGRES_DB=shelf +POSTGRES_TEST_DB="shelf_test" +POSTGRES_USER=postgres +POSTGRES_PASSWORD=postgres +ENV=dev + +BCRYPT_PASSWORD=speak-friend-and-enter +SALT_ROUNDS=10 +TOKEN_SECRET=alohomora123! +TOKEN_SECRET_TEST=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoxLCJmaXJzdG5hbWUiOiJKb2huIiwibGFzdG5hbWUiOiJEb2UiLCJ1c2VybmFtZSI6InRlc3QiLCJwYXNzd29yZF9kaWdlc3QiOiIkMmIkMTAkeXNkTHQuUjVqdjFJdHVzTk5NMGJNLlU0RkZvbmJRYUV2VFBsVnFhQWJqSkV3NTdzTEZwVGEifSwiaWF0IjoxNjUzMjUzODIxfQ.rdC42gcdhzAwnwwVJxmhBLVK5tvf2zONG3UcHLU6xE0` +``` + +- Inside shelf folder mount the container: `docker compose up` +- Create shelf_test database with the following commands: +-- `docker exec -it shelf-postgres-1 /bin/bash` +-- `psql -U postgres` +-- `CREATE DATABASE shelf_test` # Installation -1 - Install packages dependencies. `npm install` -2 - Inside shelf folder mount the database. `docker compose up` -3 - Run tests. `npm run test` -4 - Run the database `npm run up` -5 - Launch the application `npm run start` +- Install packages dependencies: `npm install` +- Run tests: `npm run test` +- Run the database: `npm run up` +- Launch the application: `npm run start` -Note : If needed you can reset the tables by closing the app and running the following commands : +Note : If needed you can reset the tables by closing the app and running the following commands: - `npm run down` - `npm run up` @@ -53,14 +75,15 @@ Note : If needed you can reset the tables by closing the app and running the fol # Built with - Typescript -- Postgres - Node - Express - Dotenv +- Docker +- Postgres - Db-migrate - Jsonwebtoken - Jasmine -- Supertest +- Supertest # Author diff --git a/package.json b/package.json index d17e00f..291fd4a 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,8 @@ "description": "", "main": "server.ts", "scripts": { - "start": "nodemon src/server.ts", - "dev": "db-migrate --env dev up && nodemon src/server.ts", + "start": "node dist/server.js", + "dev": "nodemon src/server.ts", "watch": "tsc-watch --esModuleInterop src/server.ts --outDir ./dist --onSuccess \"node ./dist/server.js\"", "test": "db-migrate --env test up && ENV=test jasmine-ts --config jasmine.json && db-migrate --env test down", "build": "npx tsc", diff --git a/src/database.ts b/src/database.ts index f4845fc..5e6550e 100644 --- a/src/database.ts +++ b/src/database.ts @@ -13,7 +13,6 @@ const { } = process.env; let client = new Pool(); -console.log(ENV); if (ENV === "dev") { client = new Pool({ diff --git a/src/server.ts b/src/server.ts index 906f703..2b46254 100644 --- a/src/server.ts +++ b/src/server.ts @@ -6,7 +6,7 @@ import userRoutes from "./handlers/users"; import orderRoutes from "./handlers/orders"; const app: express.Application = express(); -const address: string = "0.0.0.0:3000"; +const address: string = "127.0.0.1:3000"; const port = 3000; app.use(bodyParser.json()); diff --git a/tsconfig.json b/tsconfig.json index 4cf8fea..7775f94 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,7 +14,7 @@ // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ // "sourceMap": true, /* Generates corresponding '.map' file. */ // "outFile": "./", /* Concatenate and emit output to single file. */ - // "outDir": "./", /* Redirect output structure to the directory. */ + "outDir": "./dist", /* Redirect output structure to the directory. */ "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ // "composite": true, /* Enable project compilation */ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */