From 67ea2867e79ad81b6382d4cc463aee14ce344fed Mon Sep 17 00:00:00 2001 From: Andrei <123andrei.santos@gmail.com> Date: Mon, 12 Sep 2022 21:00:13 -0300 Subject: [PATCH] introducao-autenticacao --- modulo4/introducao-autenticacao/package.json | 26 +++++++++++++++++++ modulo4/introducao-autenticacao/src/app.ts | 19 ++++++++++++++ .../introducao-autenticacao/src/connection.ts | 18 +++++++++++++ modulo4/introducao-autenticacao/src/index.ts | 0 modulo4/introducao-autenticacao/tsconfig.json | 14 ++++++++++ 5 files changed, 77 insertions(+) create mode 100644 modulo4/introducao-autenticacao/package.json create mode 100644 modulo4/introducao-autenticacao/src/app.ts create mode 100644 modulo4/introducao-autenticacao/src/connection.ts create mode 100644 modulo4/introducao-autenticacao/src/index.ts create mode 100644 modulo4/introducao-autenticacao/tsconfig.json diff --git a/modulo4/introducao-autenticacao/package.json b/modulo4/introducao-autenticacao/package.json new file mode 100644 index 0000000..b9c29c0 --- /dev/null +++ b/modulo4/introducao-autenticacao/package.json @@ -0,0 +1,26 @@ +{ + "name": "aula-knex", + "version": "1.0.0", + "main": "index.js", + "scripts": { + "start": "tsc && node ./build/index.js", + "dev-start": "ts-node-dev ./src/index.ts" + }, + "author": "Labenu", + "license": "ISC", + "dependencies": { + "cors": "^2.8.5", + "dotenv": "^8.2.0", + "express": "^4.17.1", + "knex": "^0.95.2", + "mysql": "^2.18.1" + }, + "devDependencies": { + "@types/cors": "^2.8.10", + "@types/express": "^4.17.11", + "@types/knex": "^0.16.1", + "@types/node": "^14.14.35", + "ts-node-dev": "^1.1.6", + "typescript": "^4.2.3" + } +} diff --git a/modulo4/introducao-autenticacao/src/app.ts b/modulo4/introducao-autenticacao/src/app.ts new file mode 100644 index 0000000..dc8bf78 --- /dev/null +++ b/modulo4/introducao-autenticacao/src/app.ts @@ -0,0 +1,19 @@ +import express from "express"; +import cors from "cors"; +import { AddressInfo } from "net"; + +const app = express(); + +app.use(express.json()); +app.use(cors()); + +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.`); + } +}); + +export default app \ No newline at end of file diff --git a/modulo4/introducao-autenticacao/src/connection.ts b/modulo4/introducao-autenticacao/src/connection.ts new file mode 100644 index 0000000..6020fd2 --- /dev/null +++ b/modulo4/introducao-autenticacao/src/connection.ts @@ -0,0 +1,18 @@ +import knex from "knex"; +import dotenv from "dotenv"; + +dotenv.config(); + +const connection = knex({ + client: "mysql", + connection: { + host: process.env.DB_HOST, + port: 3306, + user: process.env.DB_USER, + password: process.env.DB_PASSWORD, + database: process.env.DB_SCHEMA, + multipleStatements: true + }, +}); + +export default connection \ No newline at end of file diff --git a/modulo4/introducao-autenticacao/src/index.ts b/modulo4/introducao-autenticacao/src/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/modulo4/introducao-autenticacao/tsconfig.json b/modulo4/introducao-autenticacao/tsconfig.json new file mode 100644 index 0000000..b6574ed --- /dev/null +++ b/modulo4/introducao-autenticacao/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "target": "es6", + "module": "commonjs", + "sourceMap": true, + "outDir": "./build", + "rootDir": "./src", + "removeComments": true, + "strict": true, + "noImplicitAny": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true + } +} \ No newline at end of file