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,
|
||||
}
|
87
lib/index.js
87
lib/index.js
@@ -1,87 +1,22 @@
|
||||
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 { configureApplication } = require('./app')
|
||||
const { createAppLogger } = require('./log-utils')
|
||||
const {
|
||||
error,
|
||||
notFound,
|
||||
download,
|
||||
downloadHTML,
|
||||
} = require('./routes')
|
||||
|
||||
const {
|
||||
genericErrorHandler,
|
||||
checkURLParameter,
|
||||
forceSecure,
|
||||
createRouteLogger,
|
||||
createErrorLogger,
|
||||
} = require('./middlewares')
|
||||
const { createAppLogger } = require('./log-utils')
|
||||
|
||||
const port = process.env.PORT
|
||||
const certEndpoint = process.env.CERT_ENDPOINT || ''
|
||||
const certSecret = process.env.CERT_SECRET || ''
|
||||
const isDevelopment = process.env.NODE_ENV === 'development'
|
||||
const enforceHTTPS = Boolean(process.env.ENFORCE_HTTPS)
|
||||
const port = process.env.PORT
|
||||
|
||||
const app = express()
|
||||
const appLogger = createAppLogger({ dev: isDevelopment })
|
||||
const limiter = rateLimit({
|
||||
windowMs: 60 * 1000,
|
||||
max: 10,
|
||||
const errorLogger = createErrorLogger({ dev: isDevelopment })
|
||||
const routeLogger = isDevelopment ? createRouteLogger({ dev: isDevelopment }) : null
|
||||
|
||||
const app = configureApplication({
|
||||
appLogger,
|
||||
errorLogger,
|
||||
routeLogger,
|
||||
rateLimitEnabled: true
|
||||
})
|
||||
const pkg = require('../package.json')
|
||||
const version = pkg.version || ''
|
||||
|
||||
// Force app to always redirect to HTTPS
|
||||
// use when you can't configure web server
|
||||
if (enforceHTTPS) {
|
||||
app.use(forceSecure)
|
||||
}
|
||||
|
||||
// Server logs
|
||||
// You can alternatively enable these to mimic logs created
|
||||
// by your web server
|
||||
if (isDevelopment) {
|
||||
app.use(createRouteLogger({ dev: isDevelopment }))
|
||||
}
|
||||
|
||||
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 }))
|
||||
|
||||
const indexFile = path.join(__dirname, '..', 'dist', 'index.html')
|
||||
|
||||
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', limiter)
|
||||
app.use('/download/html', checkURLParameter)
|
||||
app.post('/download/html', downloadHTML(appLogger))
|
||||
|
||||
app.use('/download', limiter)
|
||||
app.use('/download', checkURLParameter)
|
||||
app.post('/download', download)
|
||||
|
||||
app.use(createErrorLogger({ dev: isDevelopment }))
|
||||
app.use(genericErrorHandler)
|
||||
|
||||
app.listen(port)
|
||||
|
@@ -18,12 +18,12 @@ const downloadHTML = (logger) => (async (req, res, next) => {
|
||||
}
|
||||
})
|
||||
|
||||
const download = async (req, res, next) => {
|
||||
const download = (logger) => (async (req, res, next) => {
|
||||
try {
|
||||
const { url } = req.body
|
||||
|
||||
const ics = await retrieveICS(url, {
|
||||
logger: appLogger,
|
||||
logger,
|
||||
crawl,
|
||||
})
|
||||
|
||||
@@ -34,7 +34,7 @@ const download = async (req, res, next) => {
|
||||
} catch (err) {
|
||||
next(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = {
|
||||
downloadHTML,
|
||||
|
@@ -28,3 +28,4 @@ const crawl = async (url, { logger }) => {
|
||||
}
|
||||
|
||||
module.exports = crawl
|
||||
|
||||
|
33
lib/static/404.html
Normal file
33
lib/static/404.html
Normal file
@@ -0,0 +1,33 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Page Not Found</title>
|
||||
|
||||
<style media="screen">
|
||||
body { background: #ECEFF1; color: rgba(0,0,0,0.87); font-family: Roboto, Helvetica, Arial, sans-serif; margin: 0; padding: 0; }
|
||||
#message { background: white; max-width: 360px; margin: 100px auto 16px; padding: 32px 24px 16px; border-radius: 3px; }
|
||||
#message h3 { color: #888; font-weight: normal; font-size: 16px; margin: 16px 0 12px; }
|
||||
#message h2 { color: #ffa100; font-weight: bold; font-size: 16px; margin: 0 0 8px; }
|
||||
#message h1 { font-size: 22px; font-weight: 300; color: rgba(0,0,0,0.6); margin: 0 0 16px;}
|
||||
#message p { line-height: 140%; margin: 16px 0 24px; font-size: 14px; }
|
||||
#message a { display: block; text-align: center; background: #039be5; text-transform: uppercase; text-decoration: none; color: white; padding: 16px; border-radius: 4px; }
|
||||
#message, #message a { box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); }
|
||||
#load { color: rgba(0,0,0,0.4); text-align: center; font-size: 13px; }
|
||||
@media (max-width: 600px) {
|
||||
body, #message { margin-top: 0; background: white; box-shadow: none; }
|
||||
body { border-top: 16px solid #ffa100; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="message">
|
||||
<h2>404</h2>
|
||||
<h1>Page Not Found</h1>
|
||||
<p>The specified file was not found on this website. Please check the URL for mistakes and try again.</p>
|
||||
<h3>Why am I seeing this?</h3>
|
||||
<p>This page was generated by the Firebase Command-Line Interface. To modify it, edit the <code>404.html</code> file in your project's configured <code>public</code> directory.</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@@ -77,5 +77,11 @@
|
||||
<a href="https://github.com/comatory/fb2iCal" target="_blank" title="Github">Source</a> ◆
|
||||
<a href="/about" target="_blank" title="About the project">About</about>
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
window.__firebaseConfiguration__ = {
|
||||
serverUrl: "<%= htmlWebpackPlugin.options.serverURL %>",
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
Reference in New Issue
Block a user