mirror of
https://github.com/comatory/fb2iCal
synced 2025-06-05 22:09:25 +02:00
fix issues with deployment due to winston logging getting in the way
This commit is contained in:
106
lib/app/index.js
Normal file
106
lib/app/index.js
Normal file
@ -0,0 +1,106 @@
|
||||
const express = require('express')
|
||||
const bodyParser = require('body-parser')
|
||||
const path = require('path')
|
||||
const favicon = require('serve-favicon')
|
||||
const rateLimit = require('express-rate-limit')
|
||||
const cors = require('cors')
|
||||
|
||||
const {
|
||||
error,
|
||||
notFound,
|
||||
download,
|
||||
downloadHTML,
|
||||
} = require('../routes')
|
||||
|
||||
const {
|
||||
genericErrorHandler,
|
||||
checkURLParameter,
|
||||
forceSecure,
|
||||
} = require('../middlewares')
|
||||
|
||||
const certEndpoint = process.env.CERT_ENDPOINT || ''
|
||||
const certSecret = process.env.CERT_SECRET || ''
|
||||
const enforceHTTPS = Boolean(process.env.ENFORCE_HTTPS)
|
||||
|
||||
const configureApplication = ({
|
||||
appLogger,
|
||||
errorLogger,
|
||||
routeLogger,
|
||||
corsOptions,
|
||||
rateLimitEnabled,
|
||||
}) => {
|
||||
const pkg = require('../../package.json')
|
||||
const version = pkg.version
|
||||
|
||||
const app = express()
|
||||
|
||||
if (corsOptions) {
|
||||
app.use(cors(corsOptions))
|
||||
}
|
||||
|
||||
// Force app to always redirect to HTTPS
|
||||
// use when you can't configure web server
|
||||
if (enforceHTTPS) {
|
||||
app.use(forceSecure)
|
||||
}
|
||||
|
||||
if (appLogger) {
|
||||
app.post('/download/html', downloadHTML(appLogger))
|
||||
app.post('/download', download(appLogger))
|
||||
}
|
||||
|
||||
// Server logs You can alternatively enable these to mimic logs created
|
||||
// by your web server
|
||||
if (routeLogger) {
|
||||
app.use(routeLogger)
|
||||
}
|
||||
|
||||
if (errorLogger) {
|
||||
app.use(errorLogger)
|
||||
}
|
||||
|
||||
app.set('view engine', 'ejs')
|
||||
app.set('views', path.join(__dirname, '..', 'views'))
|
||||
app.set('trust proxy', 1)
|
||||
|
||||
app.use(express.static(path.join(__dirname, '..', '..', 'dist')))
|
||||
// app.use(favicon(path.join(__dirname, '..', 'dist', 'favicon.ico')))
|
||||
app.use(bodyParser.urlencoded({ extended: true }))
|
||||
|
||||
if (rateLimitEnabled) {
|
||||
const limiter = rateLimit({
|
||||
windowMs: 60 * 1000,
|
||||
max: 10,
|
||||
})
|
||||
|
||||
app.use('/download/html', limiter)
|
||||
app.use('/download', limiter)
|
||||
}
|
||||
|
||||
if (certEndpoint) {
|
||||
app.get(`/${certEndpoint}`, (req, res) => {
|
||||
res.status(200).send(certSecret)
|
||||
})
|
||||
}
|
||||
|
||||
app.get('/error', error)
|
||||
|
||||
app.get('/about', (req, res) => {
|
||||
res.render('about', { version })
|
||||
})
|
||||
|
||||
// NOTE: Capture all unkown URLs
|
||||
app.get('*', notFound)
|
||||
|
||||
app.use('/download/html', checkURLParameter)
|
||||
|
||||
app.use('/download', checkURLParameter)
|
||||
|
||||
app.use(genericErrorHandler)
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
configureApplication,
|
||||
}
|
Reference in New Issue
Block a user