-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
5 changed files
with
3,271 additions
and
97 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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
const path = require('path'); | ||
const path = require("path"); | ||
|
||
module.exports = { | ||
'config': path.resolve('config', 'dbConfig.js'), | ||
'models-path': path.resolve('app', 'models'), | ||
'seeders-path': path.resolve('db', 'seeders'), | ||
'migrations-path': path.resolve('db', 'migrations') | ||
} | ||
config: path.resolve("config", "dbConfig.js"), | ||
"models-path": path.resolve("app", "models"), | ||
"seeders-path": path.resolve("db", "seeders"), | ||
"migrations-path": path.resolve("db", "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 |
---|---|---|
@@ -1,50 +1,52 @@ | ||
var createError = require('http-errors'); | ||
var express = require('express'); | ||
var path = require('path'); | ||
var cookieParser = require('cookie-parser'); | ||
var logger = require('morgan'); | ||
var createError = require("http-errors"); | ||
var express = require("express"); | ||
var path = require("path"); | ||
var cookieParser = require("cookie-parser"); | ||
var logger = require("morgan"); | ||
var app = express(); | ||
var dotenv = require('dotenv').config() | ||
const response = require('./utils/formatResponse') | ||
const indexRouter = require('./routes/index') | ||
require("dotenv").config(); | ||
const response = require("./utils/formatResponse"); | ||
const indexRouter = require("./routes/index"); | ||
|
||
const swaggerJSON = require('./swagger.json'); | ||
const swaggerUI = require('swagger-ui-express'); | ||
const swaggerJSON = require("./swagger.json"); | ||
const swaggerUI = require("swagger-ui-express"); | ||
|
||
const cors = require('cors'); | ||
const cors = require("cors"); | ||
app.use(cors()); | ||
app.use(function(req, res, next) { | ||
app.use(function (req, res, next) { | ||
res.header("Access-Control-Allow-Origin", "*"); | ||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); | ||
res.header( | ||
"Access-Control-Allow-Headers", | ||
"Origin, X-Requested-With, Content-Type, Accept" | ||
); | ||
next(); | ||
}); | ||
|
||
app.use(logger('dev')); | ||
app.use(logger("dev")); | ||
app.use(express.json()); | ||
app.use(express.urlencoded({ extended: false })); | ||
app.use(cookieParser()); | ||
app.use(express.static(path.join(__dirname, 'public'))); | ||
|
||
app.use('/', indexRouter); | ||
app.use('/docs', swaggerUI.serve, swaggerUI.setup(swaggerJSON)); | ||
app.use(express.static(path.join(__dirname, "public"))); | ||
|
||
app.use("/", indexRouter); | ||
app.use("/docs", swaggerUI.serve, swaggerUI.setup(swaggerJSON)); | ||
|
||
// catch 404 and forward to error handler | ||
app.use(function(req, res, next) { | ||
app.use(function (req, res, next) { | ||
next(createError(404)); | ||
}); | ||
|
||
// error handler | ||
app.use(function(err, req, res, next) { | ||
app.use(function (err, req, res, next) { | ||
// set locals, only providing error in development | ||
res.locals.message = err.message; | ||
res.locals.error = req.app.get('env') === 'development' ? err : {}; | ||
res.locals.error = req.app.get("env") === "development" ? err : {}; | ||
|
||
const status = err.status || 500; | ||
if (err.name === "NotFoundError") { | ||
return response(res, status, false, "Url Not Found", null) | ||
} | ||
return response(res, false, status, err.message, null) | ||
return response(res, status, false, "Url Not Found", null); | ||
} | ||
return response(res, false, status, err.message, null); | ||
}); | ||
|
||
module.exports = app; | ||
module.exports = 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
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 |
---|---|---|
@@ -1,47 +1,20 @@ | ||
require("dotenv").config(); | ||
|
||
module.exports = { | ||
development: { | ||
username: "postgres", | ||
password: "123", | ||
database: "db_2ndhand", | ||
host: "127.0.0.1", | ||
dialect: "postgres" | ||
}, | ||
test: { | ||
username: "postgres", | ||
password: "admin", | ||
database: "db_2ndhand", | ||
host: "127.0.0.1", | ||
dialect: "postgres" | ||
}, | ||
production: { | ||
username: process.env.PROD_DB_USERNAME, | ||
password: process.env.PROD_DB_PASSWORD, | ||
database: process.env.PROD_DB_NAME, | ||
host: process.env.PROD_DB_HOST, | ||
port: parseInt(process.env.PROD_DB_PORT), | ||
url: `postgres://${process.env.PROD_DB_USERNAME}:${process.env.PROD_DB_PASSWORD}@${process.env.PROD_DB_HOST}:${process.env.PROD_DB_PORT}/${process.env.PROD_DB_NAME}`, | ||
dialect: "postgres", | ||
dialectOptions: { | ||
ssl: { | ||
require: true, | ||
rejectUnauthorized: false | ||
} | ||
} | ||
}, | ||
test_production: { | ||
username: process.env.TEST_DB_USERNAME, | ||
password: process.env.TEST_DB_PASSWORD, | ||
database: process.env.TEST_DB_NAME, | ||
host: process.env.TEST_DB_HOST, | ||
port: parseInt(process.env.TEST_DB_PORT), | ||
url: `postgres://${process.env.TEST_DB_USERNAME}:${process.env.TEST_DB_PASSWORD}@${process.env.TEST_DB_HOST}:${process.env.TEST_DB_PORT}/${process.env.TEST_DB_NAME}`, | ||
dialect: "postgres", | ||
dialectOptions: { | ||
ssl: { | ||
require: true, | ||
rejectUnauthorized: false | ||
} | ||
} | ||
} | ||
}; | ||
development: { | ||
username: process.env.PROD_DB_USERNAME, | ||
password: process.env.PROD_DB_PASSWORD, | ||
database: process.env.PROD_DB_NAME, | ||
host: process.env.PROD_DB_HOST, | ||
port: parseInt(process.env.PROD_DB_PORT), | ||
dialect: "postgres", | ||
}, | ||
production: { | ||
username: process.env.PROD_DB_USERNAME, | ||
password: process.env.PROD_DB_PASSWORD, | ||
database: process.env.PROD_DB_NAME, | ||
host: process.env.PROD_DB_HOST, | ||
port: parseInt(process.env.PROD_DB_PORT), | ||
dialect: "postgres", | ||
}, | ||
}; |
Oops, something went wrong.