2019-11-15 16:51:24 +00:00
|
|
|
//! Deps
|
2019-11-19 06:52:41 +00:00
|
|
|
const express = require('express');
|
|
|
|
const helmet = require('helmet');
|
|
|
|
const compression = require('compression');
|
|
|
|
const cors = require('cors');
|
|
|
|
const morgan = require('morgan');
|
|
|
|
const chalk = require('chalk');
|
2019-11-28 19:03:30 +00:00
|
|
|
const hbs = require('express-handlebars');
|
|
|
|
const UA = require('ua-parser-js');
|
2019-11-30 13:14:32 +00:00
|
|
|
const exec = require('shell-exec');
|
2019-11-30 15:26:13 +00:00
|
|
|
const simpleIcons = require('simple-icons');
|
2019-11-30 13:14:32 +00:00
|
|
|
|
2019-11-28 19:03:30 +00:00
|
|
|
const con = require('./constants');
|
2019-11-19 06:52:41 +00:00
|
|
|
let { port, hostname } = {
|
2019-12-03 09:31:05 +00:00
|
|
|
port: 3621
|
|
|
|
//hostname: '67.182.206.28'
|
2019-11-19 06:52:41 +00:00
|
|
|
};
|
2019-11-15 16:51:24 +00:00
|
|
|
|
2019-11-19 06:52:41 +00:00
|
|
|
const app = express();
|
2019-11-15 16:51:24 +00:00
|
|
|
|
|
|
|
app.set('view engine', 'hbs');
|
2019-11-19 06:52:41 +00:00
|
|
|
app.engine(
|
|
|
|
'hbs',
|
|
|
|
hbs({
|
|
|
|
extname: 'hbs',
|
|
|
|
defaultView: 'default'
|
|
|
|
})
|
|
|
|
);
|
2019-11-15 16:51:24 +00:00
|
|
|
app.set('json spaces', 4);
|
2019-11-19 06:52:41 +00:00
|
|
|
app.use('/assets', express.static('./assets'));
|
2019-11-15 16:51:24 +00:00
|
|
|
app.set('view options', {
|
2019-11-19 06:52:41 +00:00
|
|
|
layout: false
|
2019-11-15 16:51:24 +00:00
|
|
|
});
|
|
|
|
app.use(express.json());
|
2019-11-19 06:52:41 +00:00
|
|
|
app.use(
|
|
|
|
express.urlencoded({
|
|
|
|
extended: true
|
|
|
|
})
|
|
|
|
);
|
2019-11-15 16:51:24 +00:00
|
|
|
app.use(helmet());
|
|
|
|
app.use(compression());
|
|
|
|
app.use(cors());
|
|
|
|
// Logging
|
|
|
|
app.use(
|
2019-11-19 06:52:41 +00:00
|
|
|
morgan((tokens, req, res) => {
|
|
|
|
return [
|
|
|
|
chalk.hex('#34ace0').bold(tokens.method(req, res)),
|
|
|
|
chalk.hex('#ffb142').bold(tokens.status(req, res)),
|
|
|
|
chalk.hex('#ff5252').bold(req.hostname + tokens.url(req, res)),
|
|
|
|
chalk.hex('#2ed573').bold(tokens['response-time'](req, res) + 'ms'),
|
|
|
|
chalk.hex('#f78fb3').bold('@ ' + tokens.date(req, res))
|
|
|
|
].join(' ');
|
|
|
|
})
|
2019-11-15 16:51:24 +00:00
|
|
|
);
|
|
|
|
|
2019-11-28 19:03:30 +00:00
|
|
|
app.use('/portfolio', require('./routes/portfolio'));
|
2019-11-19 06:52:41 +00:00
|
|
|
app.use('/lore', require('./routes/lore'));
|
2019-11-28 19:03:30 +00:00
|
|
|
app.use('/art', require('./routes/art'));
|
2019-11-15 16:51:24 +00:00
|
|
|
|
2019-11-19 06:52:41 +00:00
|
|
|
module.exports = (client) => {
|
|
|
|
app.get('/', async (req, res) => {
|
2019-11-28 19:03:30 +00:00
|
|
|
/* var ua = UA(req.headers['user-agent']);
|
|
|
|
console.log(ua) */
|
2019-11-19 06:52:41 +00:00
|
|
|
res.render('index', {
|
|
|
|
layout: 'main',
|
2019-11-28 19:03:30 +00:00
|
|
|
name: con.name,
|
|
|
|
host: req.hostname,
|
2019-11-30 13:14:32 +00:00
|
|
|
item: [ { name: 'portfolio', source: '/portfolio' } ],
|
|
|
|
social: [
|
2019-11-30 15:26:13 +00:00
|
|
|
{ name: 'Twitter', color: '1DA1F2', link: 'twitter.com/codepupper', icon: simpleIcons.Twitter },
|
|
|
|
{ name: 'Discord', color: '7289da', link: 'thaldr.in/discord', icon: simpleIcons.Discord },
|
|
|
|
{ name: 'Mastodon', color: '3088d4', link: 'pounced-on.me/@code', icon: simpleIcons.Mastodon },
|
|
|
|
{ name: 'Keybase', color: '33a0ff', link: 'keybase.io/codepupper', icon: simpleIcons.Keybase },
|
|
|
|
{ name: 'Gitdab', color: 'faacb7', link: 'gitdab.com/y', icon: simpleIcons.Git },
|
|
|
|
{ name: 'Github', color: '333', link: 'github.com/codepupper', icon: simpleIcons.GitHub },
|
|
|
|
{ name: 'Gitlab', color: 'E24329', link: 'gitlab.com/codepupper', icon: simpleIcons.GitLab },
|
|
|
|
{ name: 'Twitch', color: '6441a4', link: 'twitch.tv/codepupper', icon: simpleIcons.Twitch }
|
2019-11-30 13:14:32 +00:00
|
|
|
]
|
2019-11-19 06:52:41 +00:00
|
|
|
});
|
|
|
|
});
|
2019-11-30 13:14:32 +00:00
|
|
|
app.get('/update', async (req, res) => {
|
|
|
|
if (req.headers.authorization !== 'Update') {
|
|
|
|
res.status(400).jsonp({
|
|
|
|
success: false,
|
|
|
|
message: 'You are not authorized to access this Endpoint'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
await exec('git pull')
|
|
|
|
.then((r) => {
|
|
|
|
console.log('Pulled latest changes');
|
|
|
|
res.status(200).jsonp({
|
|
|
|
success: true,
|
|
|
|
message: 'Successfully pulled latest changes'
|
|
|
|
});
|
|
|
|
trying.edit('```fix\n' + r.stdout + '```');
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
res.status(400).jsonp({
|
|
|
|
success: false,
|
|
|
|
message: error.message
|
|
|
|
});
|
|
|
|
console.error(error);
|
|
|
|
});
|
|
|
|
});
|
2019-11-15 16:51:24 +00:00
|
|
|
|
2019-12-03 09:31:05 +00:00
|
|
|
app.listen(port /* , hostname */, () => {
|
2019-12-03 09:24:12 +00:00
|
|
|
console.log(`Listening on ${port}`);
|
|
|
|
});
|
2019-11-19 06:52:41 +00:00
|
|
|
};
|