diff options
-rw-r--r-- | connect-better-sqlite3.js | 2 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | server.js | 47 |
3 files changed, 19 insertions, 32 deletions
diff --git a/connect-better-sqlite3.js b/connect-better-sqlite3.js index de858ed..008114b 100644 --- a/connect-better-sqlite3.js +++ b/connect-better-sqlite3.js @@ -30,7 +30,7 @@ module.exports = function (session) { let db = new SQLite(db_path, options.mode); db.pragma("journal_mode = WAL"); - db.pragma("synchronous = NORMAL"); + db.pragma("synchronous = OFF"); db.exec("CREATE TABLE IF NOT EXISTS "+table+" (sid PRIMARY KEY, expires INTEGER, sess TEXT)"); db.exec("DELETE FROM "+table+" WHERE "+now()+" > expires"); db.exec("VACUUM"); diff --git a/package.json b/package.json index 5a58b5c..2306457 100644 --- a/package.json +++ b/package.json @@ -11,12 +11,10 @@ "ejs": "^3.1.5", "express": "^4.17.1", "express-session": "^1.17.1", - "morgan": "^1.10.0", "nodemailer": "^6.7.0", "passport": "^0.5.0", "passport-local": "^1.0.0", "passport.socketio": "^3.7.0", - "rotating-file-stream": "^2.1.6", "socket.io": "^4.3.1" } } @@ -1,6 +1,9 @@ "use strict"; const fs = require('fs'); +const http = require('http'); +const https = require('https'); +const socket_io = require('socket.io'); const express = require('express'); const express_session = require('express-session'); const passport = require('passport'); @@ -28,28 +31,27 @@ db.pragma("journal_mode = WAL"); db.pragma("synchronous = NORMAL"); let app = express(); -let server = null; + let http_port = process.env.HTTP_PORT || 8080; +let http_server = http.createServer(app); +let http_io = socket_io(http_server); +http_server.listen(http_port, '0.0.0.0', () => console.log('listening HTTP on *:' + http_port)); +let io = http_io; + let https_port = process.env.HTTPS_PORT; if (https_port) { - server = require('https').createServer({ + let https_server = https.createServer({ key: fs.readFileSync(process.env.SSL_KEY || "key.pem"), cert: fs.readFileSync(process.env.SSL_CERT || "cert.pem") }, app); - server.listen(https_port, '0.0.0.0', () => { console.log('listening HTTPS on *:' + https_port); }); - - // Redirect HTTP to HTTPS if we're running HTTPS - let http_app = express(); - let http_server = require('http').createServer(http_app); - http_app.use((req, res) => res.redirect(301, 'https://' + req.hostname + req.originalUrl)); - http_server.listen(http_port, '0.0.0.0', () => { console.log('listening HTTP on *:' + http_port); }); -} else { - server = require('http').createServer(app); - server.listen(http_port, '0.0.0.0', () => { console.log('listening HTTP on *:' + http_port); }); + let https_io = socket_io(https_server); + https_server.listen(https_port, '0.0.0.0', () => console.log('listening HTTPS on *:' + https_port)); + io = { + use: function (fn) { http_io.use(fn); https_io.use(fn); }, + on: function (ev,fn) { http_io.on(ev,fn); https_io.on(ev,fn); }, + }; } -let io = require('socket.io')(server); - let mailer = null; if (process.env.MAIL_HOST && process.env.MAIL_PORT) { mailer = require('nodemailer').createTransport({ @@ -62,12 +64,7 @@ if (process.env.MAIL_HOST && process.env.MAIL_PORT) { console.log("Mail notifications disabled."); } -const morgan = require('morgan'); -const rfs = require('rotating-file-stream'); -const log_file = rfs.createStream('access.log', { interval: '1d', path: 'log' }); -app.use(morgan('combined', {stream: log_file})); - -app.disable('etag'); +app.disable('x-powered-by'); app.set('view engine', 'ejs'); app.use(body_parser.urlencoded({extended:false})); app.use(express_session({ @@ -89,14 +86,7 @@ io.use(passport_socket.authorize({ store: session_store, })); -const is_immutable = /\.(svg|png|jpg|jpeg|woff2)$/; - -function setHeaders(res, path) { - if (is_immutable.test(path)) - res.set("Cache-Control", "public, max-age=86400, immutable"); -} - -app.use(express.static('public', { setHeaders: setHeaders })); +app.use(express.static('public')); function LOG(req, ...msg) { let name; @@ -249,7 +239,6 @@ function local_signup(req, name, password, done) { return done(null, false, req.flash('message', "Password is too short!")); if (password.length > 100) return done(null, false, req.flash('message', "Password is too long!")); - // TODO: actual verification if process.env.VERIFY_EMAIL if (!is_email(mail)) return done(null, false, req.flash('message', "Invalid mail address!")); let row = sql_signup_check.get(name, mail); |