Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions sandbox/cache-example/README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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)[email protected])](http://loopback.io/)
[![LoopBack](<https://github.com/loopbackio/loopback-next/raw/master/docs/site/imgs/branding/Powered-by-LoopBack-Badge-(blue)[email protected]>)](http://loopback.io/)
6 changes: 3 additions & 3 deletions sandbox/cache-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 11 additions & 1 deletion sandbox/cache-example/src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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',
Expand Down
2 changes: 0 additions & 2 deletions sandbox/cache-example/src/repositories/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
# Repositories

This directory contains code for repositories provided by this app.
Loading