mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Modules now return a function which creates app-s, qmining module auth handle
This commit is contained in:
parent
b5f9ede2cf
commit
a03f56028a
12 changed files with 1046 additions and 990 deletions
|
@ -26,63 +26,68 @@ const app = express()
|
|||
const utils = require('../../utils/utils.js')
|
||||
const logger = require('../../utils/logger.js')
|
||||
|
||||
app.set('view engine', 'ejs')
|
||||
app.set('views', [
|
||||
'./modules/dataEditor/views',
|
||||
'./sharedViews'
|
||||
])
|
||||
app.use(express.static('modules/dataEditor/public'))
|
||||
app.use(express.static('public'))
|
||||
app.use(busboy({
|
||||
limits: {
|
||||
fileSize: 10000 * 1024 * 1024
|
||||
}
|
||||
}))
|
||||
app.use(bodyParser.json())
|
||||
app.use(bodyParser.urlencoded({
|
||||
limit: '5mb',
|
||||
extended: true
|
||||
}))
|
||||
app.use(bodyParser.json({
|
||||
limit: '5mb'
|
||||
}))
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
function AddHtmlRoutes (files) {
|
||||
const routes = files.reduce((acc, f) => {
|
||||
if (f.includes('html')) {
|
||||
acc.push(f.split('.')[0])
|
||||
return acc
|
||||
function GetApp () {
|
||||
app.set('view engine', 'ejs')
|
||||
app.set('views', [
|
||||
'./modules/dataEditor/views',
|
||||
'./sharedViews'
|
||||
])
|
||||
app.use(express.static('modules/dataEditor/public'))
|
||||
app.use(express.static('public'))
|
||||
app.use(busboy({
|
||||
limits: {
|
||||
fileSize: 10000 * 1024 * 1024
|
||||
}
|
||||
return acc
|
||||
}, [])
|
||||
}))
|
||||
app.use(bodyParser.json())
|
||||
app.use(bodyParser.urlencoded({
|
||||
limit: '5mb',
|
||||
extended: true
|
||||
}))
|
||||
app.use(bodyParser.json({
|
||||
limit: '5mb'
|
||||
}))
|
||||
|
||||
routes.forEach((route) => {
|
||||
logger.DebugLog(`Added route /${route}`, 'DataEditor routes', 1)
|
||||
app.get(`/${route}`, function (req, res) {
|
||||
logger.LogReq(req)
|
||||
res.redirect(`${route}.html`)
|
||||
// --------------------------------------------------------------
|
||||
|
||||
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}`, 'DataEditor routes', 1)
|
||||
app.get(`/${route}`, function (req, res) {
|
||||
logger.LogReq(req)
|
||||
res.redirect(`${route}.html`)
|
||||
})
|
||||
})
|
||||
}
|
||||
AddHtmlRoutes(utils.ReadDir('modules/dataEditor/public'))
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
app.get('/', function (req, res) {
|
||||
res.end('hai')
|
||||
logger.LogReq(req)
|
||||
})
|
||||
|
||||
app.get('*', function (req, res) {
|
||||
res.status(404).render('404')
|
||||
})
|
||||
|
||||
app.post('*', function (req, res) {
|
||||
res.status(404).render('404')
|
||||
})
|
||||
|
||||
return {
|
||||
app: app
|
||||
}
|
||||
}
|
||||
AddHtmlRoutes(utils.ReadDir('modules/dataEditor/public'))
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
app.get('/', function (req, res) {
|
||||
res.end('hai')
|
||||
logger.LogReq(req)
|
||||
})
|
||||
|
||||
app.get('*', function (req, res) {
|
||||
res.status(404).render('404')
|
||||
})
|
||||
|
||||
app.post('*', function (req, res) {
|
||||
res.status(404).render('404')
|
||||
})
|
||||
|
||||
exports.app = app
|
||||
|
||||
logger.Log('DataEditor module started', logger.GetColor('yellow'))
|
||||
exports.name = 'Data editor'
|
||||
exports.getApp = GetApp
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue