-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
JaquelineVictal
committed
Nov 9, 2022
1 parent
db4e235
commit 17382f9
Showing
16 changed files
with
419 additions
and
30 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,62 @@ | ||
import express from "express"; | ||
import * as http from "http"; | ||
|
||
import * as winston from "winston"; | ||
import * as expressWinston from "express-winston"; | ||
import cors from "cors"; | ||
import{ debug } from "debug"; | ||
|
||
import { UserRoutes } from "../../adapters/apis/routes/users.routes.config"; | ||
import { CommonRoutesConfig } from "../../adapters/apis/routes/common.routes.config"; | ||
import path from "path"; | ||
import bodyParser from "body-parser"; | ||
import cookieParser from "cookie-parser"; | ||
|
||
const app: express.Application = express(); | ||
const server: http.Server = http.createServer(); | ||
const PORT = process.env.PORT || 8000; | ||
const routes: CommonRoutesConfig[] = []; | ||
const debugLog: debug.IDebugger = debug('app'); | ||
|
||
app.use(express.json()); | ||
app.use(express.urlencoded()); | ||
app.use(cors()); | ||
app.use('/uploads', express.static(path.resolve('uploads'))) | ||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({extended : false})); | ||
app.use(cookieParser()); | ||
|
||
const loggerOptions: expressWinston.LoggerOptions = { | ||
transports: [new winston.transports.Console()], | ||
format: winston.format.combine( | ||
winston.format.json(), | ||
winston.format.prettyPrint(), | ||
winston.format.colorize({ all: true }) | ||
), | ||
} | ||
if(!process.env.DEBUG) { | ||
loggerOptions.meta = false; | ||
} | ||
|
||
app.use(expressWinston.logger(loggerOptions)); | ||
|
||
routes.push(new UserRoutes(app)); | ||
|
||
|
||
let runningMessage = `Servidor rodando na porta ${PORT}`; | ||
|
||
try { | ||
app.get('/', (request: express.Request, response: express.Response) => { | ||
response.status(200).send(runningMessage); | ||
}) | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
|
||
app.listen(PORT, () => { | ||
routes.forEach((route: CommonRoutesConfig)=>{ | ||
debugLog(`Rota ${route.getName()} configurada com sucesso!}`); | ||
}); | ||
console.log(runningMessage)}); | ||
|
||
export default app; |
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 @@ | ||
import 'dotenv/config'; | ||
|
||
const dbConfig = { | ||
host: process.env.DB_HOST, | ||
username: process.env.DB_USER, | ||
password: process.env.DB_PASS, | ||
port: process.env.DB_PORT, | ||
database: process.env.DB_NAME, | ||
dialect: 'mysql', | ||
} | ||
|
||
|
||
export default dbConfig; | ||
|
||
module.exports = dbConfig; |
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,5 @@ | ||
export function getErrorMessage(error: unknown) { | ||
if (error instanceof Error) return error.message; | ||
return String(error); | ||
} | ||
|
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,9 @@ | ||
import { IDatabase } from "./databese.interface"; | ||
|
||
export interface IDatabaseModel extends IDatabase { | ||
createModel(name: string, properties: any): any, | ||
read(type: any, dataId: number, includes?: object): any, | ||
list(type: any, includes?: object): any, | ||
readByWhere(type: any, data: any):any, | ||
selectQuery(sql:string,replacements:any):any | ||
} |
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,7 @@ | ||
export interface IDatabase{ | ||
list(type: any, dataWhere?:any): any[]; | ||
create(type: any, data: any): any, | ||
read(type: any, dataId:number): any, | ||
update(type : any, data: any): any, | ||
delete(type: any, dataId:any): any | ||
} |
Oops, something went wrong.