-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setup: first setup with base structure and packages
- Loading branch information
0 parents
commit 4bbc96a
Showing
193 changed files
with
18,971 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.vscode | ||
.idea | ||
.env | ||
|
||
# Generated by MacOS | ||
.DS_Store | ||
**/.DS_Store | ||
|
||
# Certificates | ||
*.crt | ||
*.key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
APP_PORT=3001 | ||
NODE_ENV=development | ||
|
||
DB_DRIVER=postgres | ||
# DB_HOST=localhost | ||
DB_HOST=shorturl-db | ||
DB_PORT=5432 | ||
DB_USERNAME=admin | ||
DB_PASSWORD=secret | ||
DB_NAME=shorturl | ||
|
||
DB_TEST_DRIVER=postgres | ||
DB_TEST_HOST=shorturl-test-db | ||
DB_TEST_PORT=5433 | ||
DB_TEST_USERNAME=admin | ||
DB_TEST_PASSWORD=secret | ||
DB_TEST_NAME=shorturl-test | ||
|
||
JWT_KEY=%#OfjeojofwjfO%J#%O%J#O%J325j230523532892fiwdfhihIHSIHSIF@FIFH | ||
HASH_PADDING=r@i23IHTI23THI2GigH2IGH239332532dsvdDSGIHGDSI@#i23H5932H5923HT9HSDIIGI3H2ri#TH23IHI23%#%%#23%23WEGUGSD222I11I4BJCSBJSBjfwbiufeueu@T#23huwegbubwug2b3i2#T@I3htwe | ||
|
||
APP_HOST=http://localhost:3000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
node_modules | ||
dist | ||
coverage | ||
yarn-error.log | ||
.vscode | ||
.idea | ||
.env | ||
todo.txt | ||
|
||
# Generated by MacOS | ||
.DS_Store | ||
**/.DS_Store | ||
|
||
# Certificates | ||
*.crt | ||
*.key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// .sequelizerc | ||
|
||
const { resolve } = require('path'); | ||
|
||
module.exports = { | ||
'config': resolve('src/config/sequelize.json'), | ||
'models-path': resolve('src/app/implementations/database/entities'), | ||
'seeders-path': resolve('src/app/implementations/database/seeders'), | ||
'migrations-path': resolve('src/app/implementations/database/migrations') | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# ShorURL API # | ||
|
||
This is an API Rest developed with NodeJs, TypeScript and Clean Architecture. | ||
|
||
* node version: 18.18.0 | ||
* Database: PostgreSQL | ||
* TypeScript | ||
* Tests made with Jest | ||
* Containers with Docker | ||
|
||
### How do I get set up? ### | ||
|
||
* .env | ||
|
||
Rename or copy the .env.example to .env | ||
|
||
cp .env.example .env | ||
|
||
The .env is configured to use docker database setup | ||
|
||
* build app | ||
|
||
In the app root (the same dir where is located the package.json and this README) run: | ||
|
||
docker compose up --build -d | ||
|
||
Just to make sure node_modules was really installed run npm install | ||
|
||
docker exec shorturl npm i | ||
|
||
To check docker live logging: | ||
|
||
docker-compose logs -f --tail 10 | ||
|
||
You should see the following containers active: | ||
|
||
 | ||
|
||
|
||
### Database Setup ### | ||
|
||
Before start to test the application you should run the migrations and seeder to setup the development database and the test database as well to run the integration tests | ||
|
||
* Running migration for development | ||
|
||
docker exec shorturl npx sequelize-cli db:migrate | ||
|
||
 | ||
|
||
* Running migration for test | ||
|
||
docker exec shorturl npx sequelize-cli db:migrate --env test | ||
|
||
* Running seeders for development | ||
|
||
docker exec shorturl npx sequelize-cli db:seed:all | ||
|
||
 | ||
|
||
* Running seeders for test | ||
|
||
docker exec shorturl npx sequelize-cli db:seed:all --env test | ||
|
||
* The final result: | ||
|
||
 | ||
|
||
### How to run unit tests? ### | ||
|
||
* Normal test | ||
|
||
docker-compose exec shorturl npx jest | ||
|
||
 | ||
|
||
* With coverage | ||
|
||
docker-compose exec shorturl npx jest --coverage | ||
|
||
Terminal version | ||
|
||
 | ||
|
||
Html version | ||
|
||
 | ||
|
||
* Postman Project | ||
|
||
See [Postman Collection](./docs/collection.json) | ||
|
||
### Who do I talk to? ### | ||
|
||
* Lucas sahdo - [email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
version: '3' | ||
|
||
networks: | ||
shorturl-network: | ||
driver: bridge | ||
ipam: | ||
driver: default | ||
|
||
services: | ||
shorturl: | ||
container_name: shorturl | ||
image: shorturl | ||
build: | ||
context: . | ||
dockerfile: ./docker/api.Dockerfile | ||
volumes: | ||
- './:/var/www/app' | ||
- '/var/www/app/node_modules' | ||
environment: | ||
- npm_config_unsafe_perm=true | ||
ports: | ||
- "3030:3000" | ||
networks: | ||
- shorturl-network | ||
|
||
shorturl-db: | ||
container_name: shorturl-db | ||
image: postgres | ||
environment: | ||
POSTGRES_DB: shorturl | ||
POSTGRES_USER: admin | ||
POSTGRES_PASSWORD: secret | ||
PGDATA: /data/postgres | ||
ports: | ||
- "5432:5432" | ||
restart: unless-stopped | ||
networks: | ||
- shorturl-network | ||
|
||
shorturl-test-db: | ||
container_name: shorturl-test-db | ||
image: postgres | ||
environment: | ||
POSTGRES_DB: shorturl-test | ||
POSTGRES_USER: admin | ||
POSTGRES_PASSWORD: secret | ||
PGDATA: /data/postgres | ||
ports: | ||
- "5433:5432" | ||
restart: unless-stopped | ||
networks: | ||
- shorturl-network |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM node:18.18.0 | ||
|
||
WORKDIR /var/www/app | ||
|
||
RUN apt-get update && apt-get -f -y install unzip wget curl vim | ||
|
||
COPY package.json /var/www/app | ||
|
||
RUN ls -lha ../ & pwd | ||
|
||
RUN npm install | ||
|
||
EXPOSE 3000 | ||
|
||
CMD ["npm", "run", "dev"] |
Oops, something went wrong.