Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staging #52

Closed
wants to merge 18 commits into from
Closed
210 changes: 210 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"winston-daily-rotate-file": "^4.7.1"
},
"devDependencies": {
"concurrently": "^8.2.0",
"nodemon": "^2.0.22",
"prettier": "^2.8.8"
},
Expand Down
50 changes: 30 additions & 20 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
const express = require('express')
const cors = require('cors')
// const winston = require('winston')
// const expressWinston = require('express-winston')
// const requestIp = require('request-ip');
const routes = require('./routes')
const express = require('express');
const cors = require('cors');

// Import custom error handlers and logger
const {
handler404,
errorsLogger,
errorsHandler,
} = require('./handlers/errors/index')
require('winston-daily-rotate-file')
const { ipLogger } = require('./handlers/logger/ip')
const path = require('path')
} = require('./handlers/errors/index');
const { ipLogger } = require('./handlers/logger/ip');
const routes = require('./routes');


// Express APP
const app = express()
app.use(cors())
app.set('trust proxy', 1)
const app = express();

// Enable CORS for all routes
app.use(cors());

// Trust the first proxy (when running behind a reverse proxy like Nginx)
app.set('trust proxy', 1);

// Middleware to parse JSON-encoded bodies
app.use(express.json());

// Middleware to parse URL-encoded bodies
app.use(express.urlencoded({ extended: true }));


// Logger
// Logger middleware
// Uncomment the following block if you want to enable IP logging
if (process.env.LOGGER === 'true') {
app.use(ipLogger)
app.use(ipLogger);
}

// Main website (waifu.it)
app.use('/', express.static(path.join(__dirname, 'frontend')))
// Custom API routes
app.use(routes);

app.use(routes)
app.use(handler404, errorsLogger, errorsHandler)
// Error handling middleware
app.use(handler404, errorsLogger, errorsHandler);

module.exports = app
module.exports = app;
Loading