mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Qmining redirect routes, handling all pages, removed unecesary api code
This commit is contained in:
parent
cbdece54f8
commit
2caf368b95
5 changed files with 90 additions and 72 deletions
|
@ -18,8 +18,6 @@
|
||||||
|
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
let url = ''
|
|
||||||
|
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
const bodyParser = require('body-parser')
|
const bodyParser = require('body-parser')
|
||||||
const busboy = require('connect-busboy')
|
const busboy = require('connect-busboy')
|
||||||
|
@ -38,12 +36,6 @@ const dataFile = 'public/data.json'
|
||||||
const msgFile = 'stats/msgs'
|
const msgFile = 'stats/msgs'
|
||||||
const motdFile = 'public/motd'
|
const motdFile = 'public/motd'
|
||||||
const versionFile = 'public/version'
|
const versionFile = 'public/version'
|
||||||
let donateURL = ''
|
|
||||||
try {
|
|
||||||
donateURL = utils.ReadFile('./data/donateURL')
|
|
||||||
} catch (e) {
|
|
||||||
logger.Log('Couldnt read donate URL file!', logger.GetColor('red'))
|
|
||||||
}
|
|
||||||
|
|
||||||
app.set('view engine', 'ejs')
|
app.set('view engine', 'ejs')
|
||||||
app.set('views', [
|
app.set('views', [
|
||||||
|
@ -96,13 +88,7 @@ Load()
|
||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
|
|
||||||
app.get('/', function (req, res) {
|
app.get('/', function (req, res) {
|
||||||
res.end('hai')
|
res.redirect('https://www.youtube.com/watch?v=ieqGJgqiXFk')
|
||||||
})
|
|
||||||
|
|
||||||
app.get('/manual', function (req, res) {
|
|
||||||
res.render('man')
|
|
||||||
res.end()
|
|
||||||
logger.LogReq(req)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
app.post('/postfeedback', function (req, res) {
|
app.post('/postfeedback', function (req, res) {
|
||||||
|
@ -112,50 +98,6 @@ app.post('/postfeedback', function (req, res) {
|
||||||
res.end()
|
res.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
app.get('/lred', function (req, res) {
|
|
||||||
res.redirect('/legacy') // TODO: redirect to react legacy
|
|
||||||
res.end()
|
|
||||||
logger.LogReq(req)
|
|
||||||
})
|
|
||||||
|
|
||||||
app.get('/menuClick', function (req, res) {
|
|
||||||
res.redirect('/') // TODO: redirect to react /
|
|
||||||
res.end()
|
|
||||||
logger.LogReq(req)
|
|
||||||
})
|
|
||||||
|
|
||||||
app.get('/install', function (req, res) {
|
|
||||||
res.redirect(url + '/moodle-test-userscript/stable.user.js?install')
|
|
||||||
res.end()
|
|
||||||
logger.LogReq(req)
|
|
||||||
})
|
|
||||||
|
|
||||||
app.get('/donate', function (req, res) {
|
|
||||||
res.redirect(donateURL)
|
|
||||||
res.end()
|
|
||||||
logger.LogReq(req)
|
|
||||||
})
|
|
||||||
|
|
||||||
app.get('/thanks', function (req, res) {
|
|
||||||
res.render('thanks', { // TODO: redirect to react thanks
|
|
||||||
siteurl: url
|
|
||||||
})
|
|
||||||
res.end()
|
|
||||||
logger.LogReq(req)
|
|
||||||
})
|
|
||||||
|
|
||||||
app.get('/classesgit', function (req, res) {
|
|
||||||
res.redirect('https://gitlab.com/MrFry/question-classes')
|
|
||||||
res.end()
|
|
||||||
logger.LogReq(req)
|
|
||||||
})
|
|
||||||
|
|
||||||
app.get('/scriptgit', function (req, res) {
|
|
||||||
res.redirect('https://gitlab.com/MrFry/moodle-test-userscript')
|
|
||||||
res.end()
|
|
||||||
logger.LogReq(req)
|
|
||||||
})
|
|
||||||
|
|
||||||
app.get('/servergit', function (req, res) {
|
app.get('/servergit', function (req, res) {
|
||||||
res.redirect('https://gitlab.com/MrFry/mrfrys-node-server')
|
res.redirect('https://gitlab.com/MrFry/mrfrys-node-server')
|
||||||
res.end()
|
res.end()
|
||||||
|
@ -313,8 +255,5 @@ app.post('*', function (req, res) {
|
||||||
})
|
})
|
||||||
|
|
||||||
exports.app = app
|
exports.app = app
|
||||||
exports.setup = (x) => {
|
|
||||||
url = x.url
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.Log('API module started', logger.GetColor('yellow'))
|
logger.Log('API module started', logger.GetColor('yellow'))
|
||||||
|
|
|
@ -18,14 +18,23 @@
|
||||||
|
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
let url = ''
|
||||||
|
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
const bodyParser = require('body-parser')
|
const bodyParser = require('body-parser')
|
||||||
const busboy = require('connect-busboy')
|
const busboy = require('connect-busboy')
|
||||||
const app = express()
|
const app = express()
|
||||||
|
|
||||||
// const utils = require('../../utils/utils.js')
|
const utils = require('../../utils/utils.js')
|
||||||
const logger = require('../../utils/logger.js')
|
const logger = require('../../utils/logger.js')
|
||||||
|
|
||||||
|
let donateURL = ''
|
||||||
|
try {
|
||||||
|
donateURL = utils.ReadFile('./data/donateURL')
|
||||||
|
} catch (e) {
|
||||||
|
logger.Log('Couldnt read donate URL file!', logger.GetColor('red'))
|
||||||
|
}
|
||||||
|
|
||||||
app.set('view engine', 'ejs')
|
app.set('view engine', 'ejs')
|
||||||
app.set('views', [
|
app.set('views', [
|
||||||
'./modules/qmining/views',
|
'./modules/qmining/views',
|
||||||
|
@ -47,15 +56,79 @@ app.use(bodyParser.json({
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
|
// REDIRECTS
|
||||||
|
// --------------------------------------------------------------
|
||||||
|
|
||||||
|
// to be backwards compatible
|
||||||
app.get('/ask', function (req, res) {
|
app.get('/ask', function (req, res) {
|
||||||
logger.DebugLog(`Qmining module ask redirect`, 'ask', 1)
|
logger.DebugLog(`Qmining module ask redirect`, 'ask', 1)
|
||||||
res.redirect(`http://api.frylabs.net/ask?q=${req.query.q}&subj=${req.query.subj}&data=${req.query.data}`)
|
res.redirect(`http://api.frylabs.net/ask?q=${req.query.q}&subj=${req.query.subj}&data=${req.query.data}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
app.get('/infos', function (req, res) {
|
const simpleRedirects = [
|
||||||
logger.DebugLog(`Qmining module infos redirect`, 'infos', 1)
|
{
|
||||||
res.redirect('http://api.frylabs.net/infos?version=true&motd=true&subjinfo=true')
|
from: '/install',
|
||||||
|
to: url + '/moodle-test-userscript/stable.user.js?install'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
from: '/scriptgit',
|
||||||
|
to: 'https://gitlab.com/MrFry/moodle-test-userscript'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
from: '/classesgit',
|
||||||
|
to: 'https://gitlab.com/MrFry/question-classes'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
from: '/menuClick',
|
||||||
|
to: '/'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
from: '/lred',
|
||||||
|
to: '/allQuestions.html'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
from: '/donate',
|
||||||
|
to: donateURL
|
||||||
|
},
|
||||||
|
{ // to be backwards compatible
|
||||||
|
from: '/legacy',
|
||||||
|
to: '/allQuestions.html'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
from: '/infos',
|
||||||
|
to: 'http://api.frylabs.net/infos?version=true&motd=true&subjinfo=true'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
simpleRedirects.forEach((redirect) => {
|
||||||
|
app.get(redirect.from, function (req, res) {
|
||||||
|
logger.LogReq(req)
|
||||||
|
logger.DebugLog(`Qmining module ${redirect.from} redirect`, 'infos', 1)
|
||||||
|
res.redirect(`${redirect.to}`)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// --------------------------------------------------------------
|
||||||
|
|
||||||
|
function AddHtmlRoutes (files) {
|
||||||
|
const routes = files.reduce((acc, f) => {
|
||||||
|
if (f.includes('html')) {
|
||||||
|
acc.push(f.split('.')[0])
|
||||||
|
return acc
|
||||||
|
}
|
||||||
|
return acc
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
routes.forEach((route) => {
|
||||||
|
logger.DebugLog(`Added route /${route}`, 'Qmining routes', 1)
|
||||||
|
app.get(`/${route}`, function (req, res) {
|
||||||
|
logger.LogReq(req)
|
||||||
|
res.redirect(`${route}.html`)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
AddHtmlRoutes(utils.ReadDir('modules/qmining/public'))
|
||||||
|
|
||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
|
|
||||||
app.get('/', function (req, res) {
|
app.get('/', function (req, res) {
|
||||||
|
@ -64,9 +137,7 @@ app.get('/', function (req, res) {
|
||||||
})
|
})
|
||||||
|
|
||||||
app.get('*', function (req, res) {
|
app.get('*', function (req, res) {
|
||||||
res.redirect('/')
|
res.status(404).render('404')
|
||||||
res.end()
|
|
||||||
// res.status(404).render('404')
|
|
||||||
})
|
})
|
||||||
|
|
||||||
app.post('*', function (req, res) {
|
app.post('*', function (req, res) {
|
||||||
|
@ -74,5 +145,8 @@ app.post('*', function (req, res) {
|
||||||
})
|
})
|
||||||
|
|
||||||
exports.app = app
|
exports.app = app
|
||||||
|
exports.setup = (x) => {
|
||||||
|
url = x.url
|
||||||
|
}
|
||||||
|
|
||||||
logger.Log('Qmining module started', logger.GetColor('yellow'))
|
logger.Log('Qmining module started', logger.GetColor('yellow'))
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
const startHTTPS = true
|
const startHTTPS = true
|
||||||
const port = 80
|
const port = 8080
|
||||||
const httpsport = 5001
|
const httpsport = 5001
|
||||||
|
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<center>
|
<center>
|
||||||
<h1>404</h1>
|
<h1>404</h1>
|
||||||
|
|
||||||
<iframe width="660" height="465" src="https://www.youtube-nocookie.com/embed/GOzwOeONBhQ" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
|
<iframe width="660" height="465" src="https://www.youtube-nocookie.com/embed/qLrnkK2YEcE" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
|
||||||
</center>
|
</center>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,8 @@ module.exports = {
|
||||||
WriteBackup: WriteBackup,
|
WriteBackup: WriteBackup,
|
||||||
FileExists: FileExists,
|
FileExists: FileExists,
|
||||||
CreatePath: CreatePath,
|
CreatePath: CreatePath,
|
||||||
WatchFile: WatchFile
|
WatchFile: WatchFile,
|
||||||
|
ReadDir: ReadDir
|
||||||
}
|
}
|
||||||
|
|
||||||
var fs = require('fs')
|
var fs = require('fs')
|
||||||
|
@ -16,6 +17,10 @@ var logger = require('../utils/logger.js')
|
||||||
|
|
||||||
const dataFile = './public/data.json'
|
const dataFile = './public/data.json'
|
||||||
|
|
||||||
|
function ReadDir (path) {
|
||||||
|
return fs.readdirSync(path)
|
||||||
|
}
|
||||||
|
|
||||||
function ReadFile (name) {
|
function ReadFile (name) {
|
||||||
if (!FileExists(name)) { throw new Error('No such file: ' + name) }
|
if (!FileExists(name)) { throw new Error('No such file: ' + name) }
|
||||||
return fs.readFileSync(name, 'utf8')
|
return fs.readFileSync(name, 'utf8')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue