Skip to content
This repository has been archived by the owner on Jul 31, 2021. It is now read-only.

Commit

Permalink
Merge pull request #7 from EnderDev/master
Browse files Browse the repository at this point in the history
✨ Redesign of Sketchel
  • Loading branch information
kierandrewett authored Nov 20, 2019
2 parents 771447e + 0b94e90 commit f37bcff
Show file tree
Hide file tree
Showing 22 changed files with 628 additions and 290 deletions.
79 changes: 55 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
const express = require('express')
const db = require('quick.db')
const flash = require('connect-flash')
const cookieParser = require('cookie-parser')
const bodyParser = require('body-parser')
const passport = require('passport')
const session = require('express-session')
const uuidv4 = require('uuid/v4')
const date = require('date-and-time')
const bcrypt = require('bcrypt')
const https = require('https')
const express = require('express');
const db = require('quick.db');
const flash = require('connect-flash');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const passport = require('passport');
const session = require('express-session');
const uuidv4 = require('uuid/v4');
const date = require('date-and-time');
const bcrypt = require('bcrypt');
const https = require('https');
const http = require('http');
const fs = require('fs');
const open = require('opn');
const app = express();
const markdown = require('markdown')
const xss = require('xss')
Expand All @@ -27,6 +29,9 @@ var discord = {
"clientId": "645366454618816522",
"clientSecret": "d2Hfn0cHpPPwoRKtpnuyM8amIxluwxF9"
},
scopes: [
'identify',
'email'
"bot": {
"token": "NjQ1MzY2NDU0NjE4ODE2NTIy.XdBkSQ.xl9NqXwKhTtToT8uFd_G2zHTdSg"
},
Expand Down Expand Up @@ -715,6 +720,11 @@ app.get('/api/v1/get-avatar/:userId', (req, res) => {
}
});

// Serve
app.get('/cdn/serve/:path', (req, res) => {
res.sendFile(__dirname + '/public/' + req.params.path);
})

app.get('/logout', (req, res) => {
var user = getUser(req.cookies)
if (!user) {
Expand Down Expand Up @@ -901,6 +911,13 @@ app.post('/settings/submit-changes', (req, res) => {
return
});

app.get('/components/notifications', (req, res) => {
var username = getUser(req.cookies);
var dark = users.get(`${username}.dark`);

res.render('notifications', { user: username, dark: dark ? true : false })
})

app.post('/users/login', (req, res) => {
var username = req.body.username;
var password = req.body.password;
Expand Down Expand Up @@ -964,16 +981,30 @@ app.use((req, res, next) => {
});

// Start listener
const privateKey = fs.readFileSync('/etc/letsencrypt/live/sketchel.art/privkey.pem', 'utf8');
const certificate = fs.readFileSync('/etc/letsencrypt/live/sketchel.art/cert.pem', 'utf8');
const ca = fs.readFileSync('/etc/letsencrypt/live/sketchel.art/chain.pem', 'utf8');

const credentials = {
key: privateKey,
cert: certificate,
ca: ca
};
const httpsServer = https.createServer(credentials, app);
httpsServer.listen(443, () => {
console.log('Server started listening on port 443!');
});
if(!process.env.HTTPS) {
if(!fs.existsSync('/etc/letsencrypt/live/sketchel.art/privkey.pem')) {
return console.log("I recommend using `npm run dev` if you are running this locally.")
}

const privateKey = fs.readFileSync('/etc/letsencrypt/live/sketchel.art/privkey.pem', 'utf8')
const certificate = fs.readFileSync('/etc/letsencrypt/live/sketchel.art/cert.pem', 'utf8')
const ca = fs.readFileSync('/etc/letsencrypt/live/sketchel.art/chain.pem', 'utf8')

const credentials = {
key: privateKey,
cert: certificate,
ca: ca
}
const httpsServer = https.createServer(credentials, app)
httpsServer.listen(443, () => {
console.log('Server started listening on port 443!');
open(`http://localhost:443`);

})
} else {
const httpServer = http.createServer(app)
httpServer.listen(80, () => {
console.log('Server started listening on port 80!')
open(`http://localhost:80`);
})
}
Loading

0 comments on commit f37bcff

Please sign in to comment.