diff --git a/sandbox/cache-example/README.md b/sandbox/cache-example/README.md index f7bd846e5c..cccd283857 100644 --- a/sandbox/cache-example/README.md +++ b/sandbox/cache-example/README.md @@ -1,32 +1,40 @@ -# cache-example +# CacheExample This application is generated using [LoopBack 4 CLI](https://loopback.io/doc/en/lb4/Command-line-interface.html) with the [initial project layout](https://loopback.io/doc/en/lb4/Loopback-application-layout.html). -## Install dependencies +## STEP 1: Install dependencies -By default, dependencies were installed when this application was generated. -Whenever dependencies in `package.json` are changed, run the following command: +To install the project dependencies, run the following command: ```sh npm install ``` - -To only install resolved dependencies in `package-lock.json`: +## STEP 2: Set up Environment Variables +1. Copy the .env.example file to .env: ```sh -npm ci +cp .env.example .env ``` +2. Open the .env file and configure the necessary environment variables (e.g., database connection settings, redis connection settings). -## Run the application +## STEP 3: Database Migration +Run the following command to migrate the database: +```sh +npm run db:migrate +``` +## STEP 4: Start the application +Once everything is set up, you can start the Node.js application with the following command: ```sh npm start ``` +This will start the server, and you can begin testing the API. -You can also run `node .` to skip the build step. +## STEP 5: Testing the API +After starting the application, you can test the API using Swagger UI. Open your browser and visit: -Open http://127.0.0.1:3000 in your browser. +http://127.0.0.1:3000 Replace the URL according to your configuration ## Rebuild the project @@ -55,8 +63,6 @@ npm run lint:fix ``` ## Other useful commands - -- `npm run migrate`: Migrate database schemas for models - `npm run openapi-spec`: Generate OpenAPI spec into a file - `npm run docker:build`: Build a Docker image for this application - `npm run docker:run`: Run this application inside a Docker container @@ -67,9 +73,14 @@ npm run lint:fix npm test ``` +## Troubleshooting +* Ensure that your database is correctly configured and running. +* Make sure that the JWT private and public keys are properly set up in the .env file. +* If you encounter issues with Swagger UI not loading, verify that the server has successfully started and that the correct port is specified. + ## What's next Please check out [LoopBack 4 documentation](https://loopback.io/doc/en/lb4/) to understand how you can continue to add features to this application. -[![LoopBack](https://github.com/loopbackio/loopback-next/raw/master/docs/site/imgs/branding/Powered-by-LoopBack-Badge-(blue)-@2x.png)](http://loopback.io/) +[![LoopBack]()](http://loopback.io/) diff --git a/sandbox/cache-example/package.json b/sandbox/cache-example/package.json index 5aed7361df..7012a18ba0 100644 --- a/sandbox/cache-example/package.json +++ b/sandbox/cache-example/package.json @@ -34,9 +34,9 @@ "start": "node -r source-map-support/register .", "clean": "lb-clean dist *.tsbuildinfo .eslintcache", "rebuild": "npm run clean && npm run build", - "db:migrate": "./node_modules/db-migrate/bin/db-migrate up --config './migrations/database.json'", - "db:migrate:down": "./node_modules/db-migrate/bin/db-migrate down --config './migrations/database.json'", - "db:migrate:reset": "./node_modules/db-migrate/bin/db-migrate reset --config './migrations/database.json'" + "db:migrate": "../../node_modules/db-migrate/bin/db-migrate up --config './migrations/database.json'", + "db:migrate:down": "../../node_modules/db-migrate/bin/db-migrate down --config './migrations/database.json'", + "db:migrate:reset": "../../node_modules/db-migrate/bin/db-migrate reset --config './migrations/database.json'" }, "repository": { "type": "git", diff --git a/sandbox/cache-example/src/application.ts b/sandbox/cache-example/src/application.ts index 05563e284f..b326578f98 100644 --- a/sandbox/cache-example/src/application.ts +++ b/sandbox/cache-example/src/application.ts @@ -11,7 +11,11 @@ import { RestExplorerComponent, } from '@loopback/rest-explorer'; import {ServiceMixin} from '@loopback/service-proxy'; -import {CachingComponent} from '@sourceloop/cache'; +import { + CacheComponentBindings, + CachingComponent, + RedisStoreStrategy, +} from '@sourceloop/cache'; import path from 'path'; import {MySequence} from './sequence'; @@ -29,6 +33,12 @@ export class CacheExampleApplication extends BootMixin( // Set up default home page this.static('/', path.join(__dirname, '../public')); + this.bind(CacheComponentBindings.CacheConfig).to({ + ttl: 1000, + strategy: RedisStoreStrategy, + datasourceName: 'cacheDb', + }); + // Customize @loopback/rest-explorer configuration here this.configure(RestExplorerBindings.COMPONENT).to({ path: '/explorer', diff --git a/sandbox/cache-example/src/repositories/README.md b/sandbox/cache-example/src/repositories/README.md index 08638a7878..00a3b0e904 100644 --- a/sandbox/cache-example/src/repositories/README.md +++ b/sandbox/cache-example/src/repositories/README.md @@ -1,3 +1 @@ # Repositories - -This directory contains code for repositories provided by this app.