From f8a287ded3181173e4f74b5e1cdc7bf8552ea8b5 Mon Sep 17 00:00:00 2001 From: GustavoWillianFr Date: Wed, 24 Aug 2022 23:07:13 -0300 Subject: [PATCH] Exercicios --- modulo3/Pokedex/Freire-pokedex5 | 1 + modulo4/knex-js/.gitignore | 4 ++++ modulo4/knex-js/package.json | 28 ++++++++++++++++++++++++++++ modulo4/knex-js/src/connection.ts | 15 +++++++++++++++ modulo4/knex-js/src/index.ts | 19 +++++++++++++++++++ modulo4/knex-js/tsconfig.json | 13 +++++++++++++ 6 files changed, 80 insertions(+) create mode 160000 modulo3/Pokedex/Freire-pokedex5 create mode 100644 modulo4/knex-js/.gitignore create mode 100644 modulo4/knex-js/package.json create mode 100644 modulo4/knex-js/src/connection.ts create mode 100644 modulo4/knex-js/src/index.ts create mode 100644 modulo4/knex-js/tsconfig.json diff --git a/modulo3/Pokedex/Freire-pokedex5 b/modulo3/Pokedex/Freire-pokedex5 new file mode 160000 index 0000000..b4e94e0 --- /dev/null +++ b/modulo3/Pokedex/Freire-pokedex5 @@ -0,0 +1 @@ +Subproject commit b4e94e0832ce37275606b247120fe890dbffc9b7 diff --git a/modulo4/knex-js/.gitignore b/modulo4/knex-js/.gitignore new file mode 100644 index 0000000..8ece3ba --- /dev/null +++ b/modulo4/knex-js/.gitignore @@ -0,0 +1,4 @@ +node_modules +package-lock.json +build +.env \ No newline at end of file diff --git a/modulo4/knex-js/package.json b/modulo4/knex-js/package.json new file mode 100644 index 0000000..be603dd --- /dev/null +++ b/modulo4/knex-js/package.json @@ -0,0 +1,28 @@ +{ + "name": "knex", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "dev": "ts-node-dev ./src/index.ts", + "start": "tsc && node ./build/index.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "@types/cors": "^2.8.12", + "@types/express": "^4.17.13", + "ts-node-dev": "^2.0.0", + "typescript": "^4.7.4" + }, + "dependencies": { + "@types/knex": "^0.16.1", + "cors": "^2.8.5", + "dotenv": "^16.0.1", + "express": "^4.18.1", + "knex": "^2.2.0", + "mysql": "^2.18.1" + } +} diff --git a/modulo4/knex-js/src/connection.ts b/modulo4/knex-js/src/connection.ts new file mode 100644 index 0000000..28bee6a --- /dev/null +++ b/modulo4/knex-js/src/connection.ts @@ -0,0 +1,15 @@ +import knex from "knex"; +import dotenv from "dotenv"; + +// estabelecer a conexão com o banco no index.ts: +dotenv.config(); +export const connection = knex({ + client: "mysql", + connection: { + host: process.env.DB_HOST, + port: 3306, + user: process.env.DB_USER, + password: process.env.DB_PASS, + database: process.env.DB_NAME + } +}); \ No newline at end of file diff --git a/modulo4/knex-js/src/index.ts b/modulo4/knex-js/src/index.ts new file mode 100644 index 0000000..b839b0c --- /dev/null +++ b/modulo4/knex-js/src/index.ts @@ -0,0 +1,19 @@ +import express, {Express} from 'express' +import cors from 'cors' +import {connection} from './connection' + +const app: Express = express(); + +app.use(express.json()); +app.use(cors()); + +import { AddressInfo } from "net"; + +const server = app.listen(process.env.PORT || 3003, () => { + if (server) { + const address = server.address() as AddressInfo; + console.log(`Server is running in http://localhost: ${address.port}`); + } else { + console.error(`Failure upon starting server.`); + } +}); \ No newline at end of file diff --git a/modulo4/knex-js/tsconfig.json b/modulo4/knex-js/tsconfig.json new file mode 100644 index 0000000..c3d0f58 --- /dev/null +++ b/modulo4/knex-js/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "target": "es6", + "module": "commonjs" , + "sourceMap": true, + "outDir": "./build" , + "rootDir": "./src" , + "strict": true , + "noImplicitAny": true, + "esModuleInterop": true , + "forceConsistentCasingInFileNames": true + } + } \ No newline at end of file