mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Added some missing folders, changed import paths, fixed stuff with new directory layout
This commit is contained in:
parent
c6db31221e
commit
9b0d343212
7 changed files with 2472 additions and 30 deletions
|
@ -16,6 +16,6 @@ module.exports = {
|
|||
eqeqeq: ['warn', 'smart'],
|
||||
'no-unused-vars': 'off',
|
||||
'no-prototype-builtins': 'off',
|
||||
'id-length': ['error', { exceptions: [] }],
|
||||
'id-length': ['warn', { exceptions: [] }],
|
||||
},
|
||||
}
|
||||
|
|
2277
package-lock.json
generated
Normal file
2277
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "node-ejs",
|
||||
"main": "server.js",
|
||||
"main": "src/server.js",
|
||||
"dependencies": {
|
||||
"babel-eslint": "^10.1.0",
|
||||
"better-sqlite3": "^6.0.1",
|
||||
|
@ -16,7 +16,7 @@
|
|||
"vhost": "^3.0.2"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "node ./server.js",
|
||||
"dev": "node ./server.js"
|
||||
"start": "node ./src/server.js",
|
||||
"dev": "NS_DEVEL=1 NS_NOUSER=1 NS_LOGLEVEL=1 node ./src/server.js"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +1,45 @@
|
|||
#!/bin/bash
|
||||
|
||||
checkFile() {
|
||||
if [ ! -f "$@" ]; then
|
||||
echo "$@ does not exists, exiting"
|
||||
exit
|
||||
fi
|
||||
}
|
||||
|
||||
checkFile "$PWD/src/server.js"
|
||||
checkFile "$PWD/package.json"
|
||||
|
||||
git pull
|
||||
git submodule update --init --recursive
|
||||
|
||||
echo "Installing node modules for server"
|
||||
npm install
|
||||
|
||||
|
||||
echo "Making moodle test userscript"
|
||||
# TODO: ln script to publicDirs/qminingPublic/.....
|
||||
echo "Seting up next.js static stuff..."
|
||||
mkdir "$PWD/nextStatic"
|
||||
|
||||
echo "Making qmining page"
|
||||
pushd modules/qmining/qmining-page/
|
||||
npm install
|
||||
npm run export
|
||||
popd
|
||||
ln -sf "$PWD/modules/qmining/qmining-page/out" "$PWD/modules/qmining/public"
|
||||
checkFile "$PWD/submodules/qmining-page/out"
|
||||
ln -sf "$PWD/submodules/qmining-page/out" "$PWD/nextStatic/qminingPagePublic"
|
||||
|
||||
echo "Making data editor page"
|
||||
pushd modules/dataEditor/qmining-data-editor/
|
||||
npm install
|
||||
npm run export
|
||||
popd
|
||||
ln -sf "$PWD/modules/dataEditor/qmining-data-editor/out" "$PWD/modules/dataEditor/public"
|
||||
checkFile "$PWD/submodules/qmining-data-editor/out"
|
||||
ln -sf "$PWD/submodules/qmining-data-editor/out" "$PWD/nextStatic/dataEditorPublic"
|
||||
|
||||
echo "Making moodle test userscript"
|
||||
mkdir -p "$PWD/publicDirs/qminingPublic/moodle-test-userscript"
|
||||
checkFile "$PWD/submodules/moodle-test-userscript/stable.user.js"
|
||||
ln -sf "$PWD/submodules/moodle-test-userscript/stable.user.js" "$PWD/publicDirs/qminingPublic/moodle-test-userscript/"
|
||||
ln -sf "$PWD/submodules/moodle-test-userscript/stable.user.js" "$PWD/publicDirs/qminingPublic"
|
||||
|
||||
echo "mkdir-ing/touching :3"
|
||||
|
||||
|
@ -31,10 +48,10 @@ mkdir stats
|
|||
touch nolog
|
||||
|
||||
#JSONS
|
||||
echo '{}' > stats/stats
|
||||
echo '{}' > stats/vstats
|
||||
echo '{}' > stats/idstats
|
||||
echo '{}' > stats/idvstats
|
||||
echo '{}' >stats/stats
|
||||
echo '{}' >stats/vstats
|
||||
echo '{}' >stats/idstats
|
||||
echo '{}' >stats/idvstats
|
||||
|
||||
touch qminingPublic/version
|
||||
touch qminingPublic/motd
|
||||
|
@ -45,7 +62,7 @@ wget "http://qmining.frylabs.net/data.json" -O ./qminingPublic/data.json
|
|||
if [ "$?" -ne "0" ]; then
|
||||
echo "Failed to wget data.json, please create it yourself!"
|
||||
echo "Now starting with empty data!"
|
||||
echo '{"Subjects":[],"version":"TESET","motd":"hai"}' > ./qminingPublic/data.json
|
||||
echo '{"Subjects":[],"version":"TESET","motd":"hai"}' >./qminingPublic/data.json
|
||||
fi
|
||||
|
||||
pushd utils
|
||||
|
|
|
@ -1,42 +1,68 @@
|
|||
{
|
||||
"dataEditor": {
|
||||
"path": "./modules/dataEditor/dataEditor.js",
|
||||
"publicdirs": ["qminingPublic/"],
|
||||
"nextdir": "modules/dataEditor/public/",
|
||||
"publicdirs": [
|
||||
"publicDirs/qminingPublic/"
|
||||
],
|
||||
"nextdir": "nextStatic/dataEditorPublic",
|
||||
"name": "dataeditor",
|
||||
"urls": ["dataeditor.frylabs.net"],
|
||||
"urls": [
|
||||
"dataeditor.frylabs.net"
|
||||
],
|
||||
"isNextJs": true
|
||||
},
|
||||
"qmining": {
|
||||
"path": "./modules/qmining/qmining.js",
|
||||
"publicdirs": ["qminingPublic/"],
|
||||
"nextdir": "modules/qmining/public/",
|
||||
"publicdirs": [
|
||||
"publicDirs/qminingPublic/"
|
||||
],
|
||||
"nextdir": "nextStatic/qminingPagePublic",
|
||||
"name": "qmining",
|
||||
"urls": ["qmining.frylabs.net"],
|
||||
"urls": [
|
||||
"qmining.frylabs.net"
|
||||
],
|
||||
"isNextJs": true
|
||||
},
|
||||
"api": {
|
||||
"path": "./modules/api/api.js",
|
||||
"publicdirs": ["qminingPublic/"],
|
||||
"publicdirs": [
|
||||
"publicDirs/qminingPublic/"
|
||||
],
|
||||
"name": "api",
|
||||
"urls": ["api.frylabs.net", "localhost"]
|
||||
"urls": [
|
||||
"api.frylabs.net",
|
||||
"localhost"
|
||||
]
|
||||
},
|
||||
"main": {
|
||||
"path": "./modules/main/main.js",
|
||||
"publicdirs": ["public/"],
|
||||
"publicdirs": [
|
||||
"publicDirs/public/"
|
||||
],
|
||||
"name": "main",
|
||||
"urls": ["frylabs.net", "www.frylabs.net"]
|
||||
"urls": [
|
||||
"frylabs.net",
|
||||
"www.frylabs.net"
|
||||
]
|
||||
},
|
||||
"sio": {
|
||||
"path": "./modules/sio/sio.js",
|
||||
"publicdirs": ["sioPublic/"],
|
||||
"publicdirs": [
|
||||
"publicDirs/sioPublic/"
|
||||
],
|
||||
"name": "sio",
|
||||
"urls": ["sio.frylabs.net"]
|
||||
"urls": [
|
||||
"sio.frylabs.net"
|
||||
]
|
||||
},
|
||||
"stuff": {
|
||||
"path": "./modules/stuff/stuff.js",
|
||||
"publicdirs": ["stuffPublic/"],
|
||||
"publicdirs": [
|
||||
"publicDirs/stuffPublic/"
|
||||
],
|
||||
"name": "stuff",
|
||||
"urls": ["stuff.frylabs.net"]
|
||||
"urls": [
|
||||
"stuff.frylabs.net"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
118
src/modules/dataEditor/dataEditor.js
Normal file
118
src/modules/dataEditor/dataEditor.js
Normal file
|
@ -0,0 +1,118 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
|
||||
Question Server
|
||||
GitLab: <https://gitlab.com/MrFry/mrfrys-node-server>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
// package requires
|
||||
const express = require('express')
|
||||
const bodyParser = require('body-parser')
|
||||
const busboy = require('connect-busboy')
|
||||
const app = express()
|
||||
|
||||
// other requires
|
||||
const utils = require('../../utils/utils.js')
|
||||
const logger = require('../../utils/logger.js')
|
||||
const auth = require('../../middlewares/auth.middleware.js')
|
||||
|
||||
// stuff gotten from server.js
|
||||
let userDB
|
||||
let publicdirs = []
|
||||
let nextdir = ''
|
||||
|
||||
function GetApp() {
|
||||
app.use(
|
||||
bodyParser.urlencoded({
|
||||
limit: '5mb',
|
||||
extended: true,
|
||||
})
|
||||
)
|
||||
app.use(
|
||||
bodyParser.json({
|
||||
limit: '5mb',
|
||||
})
|
||||
)
|
||||
app.set('view engine', 'ejs')
|
||||
app.set('views', ['./modules/dataEditor/views', './sharedViews'])
|
||||
app.use(
|
||||
auth({
|
||||
userDB: userDB,
|
||||
jsonResponse: false,
|
||||
exceptions: ['/favicon.ico', '/getVeteranPw'],
|
||||
})
|
||||
)
|
||||
publicdirs.forEach((pdir) => {
|
||||
logger.Log(`Using public dir: ${pdir}`)
|
||||
app.use(express.static(pdir))
|
||||
})
|
||||
app.use(express.static(nextdir))
|
||||
app.use(
|
||||
busboy({
|
||||
limits: {
|
||||
fileSize: 10000 * 1024 * 1024,
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
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(nextdir))
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
exports.name = 'Data editor'
|
||||
exports.getApp = GetApp
|
||||
exports.setup = (data) => {
|
||||
userDB = data.userDB
|
||||
publicdirs = data.publicdirs
|
||||
nextdir = data.nextdir
|
||||
}
|
|
@ -17,6 +17,10 @@
|
|||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
console.log('Node version: ' + process.version)
|
||||
console.log('Current working directory: ' + process.cwd())
|
||||
|
||||
const startHTTPS = true
|
||||
const isRoot = process.getuid && process.getuid() === 0
|
||||
|
||||
|
@ -35,8 +39,8 @@ const uuidv4 = require('uuid/v4') // TODO: deprecated, but imports are not suppo
|
|||
|
||||
const dbtools = require('./utils/dbtools.js')
|
||||
const reqlogger = require('./middlewares/reqlogger.middleware.js')
|
||||
const extraModulesFile = './extraModules.json'
|
||||
const modulesFile = './modules.json'
|
||||
const extraModulesFile = './src/extraModules.json'
|
||||
const modulesFile = './src/modules.json'
|
||||
const usersDBPath = 'data/dbs/users.db'
|
||||
|
||||
if (!utils.FileExists(usersDBPath)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue