111 lines
2.9 KiB
JavaScript
111 lines
2.9 KiB
JavaScript
//! Deps
|
|
const express = require('express');
|
|
const helmet = require('helmet');
|
|
const compression = require('compression');
|
|
const cors = require('cors');
|
|
const morgan = require('morgan');
|
|
const chalk = require('chalk');
|
|
const hbs = require('express-handlebars');
|
|
const UA = require('ua-parser-js');
|
|
const exec = require('shell-exec');
|
|
|
|
const con = require('./constants');
|
|
let { port, hostname } = {
|
|
port: 3621
|
|
// hostname: 'localhost'
|
|
};
|
|
|
|
const app = express();
|
|
|
|
app.set('view engine', 'hbs');
|
|
app.engine(
|
|
'hbs',
|
|
hbs({
|
|
extname: 'hbs',
|
|
defaultView: 'default'
|
|
})
|
|
);
|
|
app.set('json spaces', 4);
|
|
app.use('/assets', express.static('./assets'));
|
|
app.set('view options', {
|
|
layout: false
|
|
});
|
|
app.use(express.json());
|
|
app.use(
|
|
express.urlencoded({
|
|
extended: true
|
|
})
|
|
);
|
|
app.use(helmet());
|
|
app.use(compression());
|
|
app.use(cors());
|
|
// Logging
|
|
app.use(
|
|
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(' ');
|
|
})
|
|
);
|
|
|
|
app.use('/portfolio', require('./routes/portfolio'));
|
|
app.use('/lore', require('./routes/lore'));
|
|
app.use('/art', require('./routes/art'));
|
|
|
|
module.exports = (client) => {
|
|
app.get('/', async (req, res) => {
|
|
/* var ua = UA(req.headers['user-agent']);
|
|
console.log(ua) */
|
|
res.render('index', {
|
|
layout: 'main',
|
|
name: con.name,
|
|
host: req.hostname,
|
|
item: [ { name: 'portfolio', source: '/portfolio' } ],
|
|
social: [
|
|
{ name: 'keybase', color: '33a0ff', link: 'keybase.io/codepupper' },
|
|
{ name: 'discord', color: '7289da', link: 'thaldr.in/discord' },
|
|
{ name: 'mastodon', color: '3088d4', link: 'pounced-on.me/@code' },
|
|
{ name: 'twitter', color: '1DA1F2', link: 'twitter.com/codepupper' },
|
|
{ name: 'gitdab', color: 'faacb7', link: 'gitdab.com/y' },
|
|
{ name: 'github', color: '333', link: 'github.com/codepupper' },
|
|
{ name: 'gitlab', color: 'E24329', link: 'gitlab.com/codepupper' },
|
|
{ name: 'twitch', color: '6441a4', link: 'twitch.tv/codepupper' }
|
|
]
|
|
});
|
|
});
|
|
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);
|
|
});
|
|
});
|
|
|
|
app.listen(
|
|
port,
|
|
/* hostname, */ () => {
|
|
console.log(`Listening on ${port}`);
|
|
}
|
|
);
|
|
};
|