mirror of
				https://github.com/KevinMidboe/zoff.git
				synced 2025-10-29 18:00:23 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			124 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			124 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
		
			Executable File
		
	
	
	
	
| VERSION = 3;
 | |
| 
 | |
| var server;
 | |
| var add = "";
 | |
| const path = require('path');
 | |
| const publicPath = path.join(__dirname, 'public');
 | |
| pathThumbnails = __dirname;
 | |
| var express = require('express');
 | |
| var app = express();
 | |
| var exphbs = require('express-handlebars');
 | |
| var hbs = exphbs.create({
 | |
| 	defaultLayout: publicPath + '/layouts/main',
 | |
| 	layoutsDir: publicPath + '/layouts',
 | |
| 	partialsDir: publicPath + '/partials'
 | |
| });
 | |
| var uniqid = require('uniqid');
 | |
| var mongo_db_cred = {config: 'mydb'};
 | |
| 
 | |
| 
 | |
| app.engine('handlebars', hbs.engine);
 | |
| //hbs.loadPartials(publicPath + "/layouts/");
 | |
| app.set('view engine', 'handlebars');
 | |
| //app.enable('view cache');
 | |
| app.set('views', publicPath);
 | |
| 
 | |
| try{
 | |
| 	var fs = require('fs');
 | |
| 	var privateKey  = fs.readFileSync('/etc/letsencrypt/live/zoff.me-0002/privkey.pem').toString();
 | |
| 	var certificate = fs.readFileSync('/etc/letsencrypt/live/zoff.me-0002/cert.pem').toString();
 | |
| 	var ca          = fs.readFileSync('/etc/letsencrypt/live/zoff.me-0002/chain.pem').toString();
 | |
| 	var credentials = {
 | |
| 		key: privateKey,
 | |
| 		cert: certificate,
 | |
| 		ca: ca
 | |
| 	};
 | |
| 
 | |
| 	var https = require('https');
 | |
| 	server = https.Server(credentials, app);
 | |
| 
 | |
| 	var cors_proxy = require('cors-anywhere');
 | |
| 
 | |
| 	cors_proxy.createServer({
 | |
| 		requireHeader: ['origin', 'x-requested-with'],
 | |
| 		removeHeaders: ['cookie', 'cookie2'],
 | |
| 		httpsOptions: credentials
 | |
| 	}).listen(8081, function() {
 | |
| 		console.log('Running CORS Anywhere on :' + 8081);
 | |
| 	});
 | |
| }
 | |
| catch(err){
 | |
| 	console.log("Starting without https (probably on localhost)");
 | |
| 	if(err.errno != 34)console.log(err);
 | |
| 	var cors_proxy = require('cors-anywhere');
 | |
| 	cors_proxy.createServer({
 | |
| 		requireHeader: ['origin', 'x-requested-with'],
 | |
| 		removeHeaders: ['cookie', 'cookie2'],
 | |
| 	}).listen(8081, function() {
 | |
| 		console.log('Running CORS Anywhere on :' + 8081);
 | |
| 	});
 | |
| 	var http = require('http');
 | |
| 	server = http.Server(app);
 | |
| 	add = ",http://localhost:80*,http://localhost:8080*,localhost:8080*, localhost:8082*,http://zoff.dev:80*,http://zoff.dev:8080*,zoff.dev:8080*, zoff.dev:8082*";
 | |
| }
 | |
| 
 | |
| var bodyParser = require('body-parser');
 | |
| var cookieParser = require('cookie-parser')
 | |
| app.use( bodyParser.json() );       // to support JSON-encoded bodies
 | |
| app.use(bodyParser.urlencoded({     // to support URL-encoded bodies
 | |
| 	extended: true
 | |
| }));
 | |
| app.use(cookieParser());
 | |
| 
 | |
| /* Starting DB and socketio */
 | |
| var io = require('socket.io')(server, {
 | |
| 	pingTimeout: 25000,
 | |
| }); //, "origins": ("https://zoff.me:443*,https://zoff.me:8080*,zoff.me:8080*,https://remote.zoff.me:443*,https://remote.zoff.me:8080*,https://fb.zoff.me:443*,https://fb.zoff.me:8080*,https://admin.zoff.me:443*,https://admin.zoff.me:8080*" + add)});
 | |
| var request = require('request');
 | |
| 
 | |
| var crypto = require('crypto');
 | |
| var node_cryptojs = require('node-cryptojs-aes');
 | |
| var CryptoJS = node_cryptojs.CryptoJS;
 | |
| var emojiStrip = require('emoji-strip');
 | |
| var Filter = require('bad-words');
 | |
| var filter = new Filter({ placeHolder: 'x'});
 | |
| 
 | |
| var router = require('./routing/router.js');
 | |
| var port = 8080;
 | |
| 
 | |
| server.listen(port, function () {
 | |
| 	console.log('Server listening at port %d', port);
 | |
| });
 | |
| 
 | |
| 
 | |
| app.get('/robots.txt', function (req, res) {
 | |
| 	res.type('text/plain');
 | |
| 	res.send("User-agent: *\nAllow: /$\nDisallow: /");
 | |
| });
 | |
| 
 | |
| app.use(function (req, res, next) {
 | |
| 	var cookie = req.cookies._uI;
 | |
| 	if (cookie === undefined) {
 | |
| 		var user_name = Functions.rndName(uniqid.time(), 15);
 | |
| 		res.cookie('_uI',user_name, { maxAge: 365 * 10000 * 3600000 });
 | |
| 	}
 | |
| 	next();
 | |
| });
 | |
| 
 | |
| app.use('/service-worker.js', function(req, res) {
 | |
| 	res.sendFile(publicPath + '/service-worker.js');
 | |
| });
 | |
| app.use('/', router);
 | |
| app.use('/assets', express.static(publicPath + '/assets'));
 | |
| 
 | |
| db.on('error',function(err) {
 | |
| 	console.log("\n" + new Date().toString() + "\n Database error: ", err);
 | |
| });
 | |
| 
 | |
| /* Resetting usernames, and connected users */
 | |
| db.collection("user_names").remove({"guid": {$exists: true}}, {multi: true, upsert: true}, function(err, docs){});
 | |
| db.collection("user_names").update({"_id": "all_names"}, {$set: {names: []}}, {multi: true, upsert: true}, function(err, docs){});
 | |
| db.collection("connected_users").update({users: {$exists: true}}, {$set: {users: []}}, {multi: true, upsert: true}, function(err, docs){});
 | |
| db.collection("connected_users").update({"_id": "total_users"}, {$set: {total_users: 0}}, {multi: true, upsert: true}, function(err, docs) {});
 | |
| db.collection("frontpage_lists").update({viewers: {$ne: 0}}, {$set: {"viewers": 0}}, {multi: true, upsert: true}, function(err, docs) {});
 |