https://github.com/moesjarraf/nestjs-example
Nest.js example using common libraries
https://github.com/moesjarraf/nestjs-example
javascript mongodb nestjs nodejs single-page-app swagger typegoose typescript
Last synced: 7 months ago
JSON representation
Nest.js example using common libraries
- Host: GitHub
- URL: https://github.com/moesjarraf/nestjs-example
- Owner: moesjarraf
- License: mit
- Created: 2023-02-22T11:58:45.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-03-09T01:25:16.000Z (over 2 years ago)
- Last Synced: 2025-01-17T21:43:53.873Z (9 months ago)
- Topics: javascript, mongodb, nestjs, nodejs, single-page-app, swagger, typegoose, typescript
- Language: HTML
- Homepage:
- Size: 1.05 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[Nest.js](https://github.com/nestjs/nest) single page application using common libraries.
## Description
This example project demonstrates how easy it is to set up a RESTful single page application, complete with entity/service/repository layers and more. The `backend` folder is where all the magic happens using common libraries. The frontend is simply generated with `@angular/cli`, no tweaks are applied there. It should also be mentioned that angular can easily be swapped to any other framework, as long as it exposes an `index.html` file.
## Libraries
This project makes use of the following libraries to do the heavy lifting.
- [moesjarraf/nestjs-common](https://github.com/moesjarraf/nestjs-common) Nest.js common libraries
- [moesjarraf/nestjs-library](https://github.com/moesjarraf/nestjs-library) Nest.js 3rd party libraries## Running the project
### Backend
```bash
$ cd backend
$ npm install
$ npm run start:dev
# backend is now running on localhost:3000
```### Frontend
```bash
$ cd frontend
$ npm install
$ npm run start
# frontend is now running on localhost:4200
```## Endpoints
You can play around with all the endpoints through the swagger API, found at `localhost:3000/api`.
Note that the `/api` path prefix is reserved for the backend, all other endpoints that do not start with that prefix are assumed to be frontend single page app paths.### Root (/)
The following behavior is applied to the root endpoint by default.
- `localhost:3000` OR `localhost:3000/api` - swagger documentation
When the `FRONTEND_INDEX` env variable is set, and is correctly pointing to an `index.html` file, the backend will serve the frontend as a single page application. To get this behavior in this example project, all you have to do is `cd frontend && npm run build`, so that the `index.html` file is created.
- `localhost:3000` - serves frontend
- `localhost:3000/api` - swagger documentation### Cats (/api/cats)
The cats endpoint contains CRUD functionality that is easily added by extending a crud controller.
### Users (/api/users)
The user endpoint demonstrates an integration with keycloak, and how to protect a resource using [nest-keycloak-connect](https://github.com/ferrerojosh/nest-keycloak-connect).
### Keycloak (/api/keycloak)
The keycloak endpoint allows you to easily login to a keycloak server, and retrieve user information.
## Configuration
For all the default configuration options that can be applied to the backend, see [this](https://github.com/moesjarraf/nestjs-common#configuration) link.
## Contributing
Commit messages should be formatted according to semantic-release standards, see [this](https://github.com/semantic-release/semantic-release#commit-message-format) link for more information. A tool has been added to the project to make adhering to the standards easier.
```bash
# add source files
git add .# format commit message
npm run commit# push
git push -u origin master
```