Redsign qortal-ui repo

This commit is contained in:
AlphaX-Projects
2023-05-11 18:40:52 +02:00
parent edbe674fb9
commit 6d3dbcdfe8
3745 changed files with 20028 additions and 10558 deletions

View File

@@ -0,0 +1,34 @@
const Path = require('path')
const Hapi = require('@hapi/hapi')
const Inert = require('@hapi/inert')
function serverFactory(routes, address, port, tls) {
this.server = new Hapi.Server({
routes: {
files: {
relativeTo: Path.join(__dirname, '../')
}
},
address: address,
port: port,
tls: tls
})
this.startServer = async () => {
try {
await this.server.register([Inert])
this.server.route(routes)
await this.server.start()
delete this.startServer
return this.server
} catch (e) {
console.error(e)
throw e
}
}
}
module.exports = serverFactory

View File

@@ -0,0 +1,106 @@
const path = require('path')
const routesOptions = {
security: {
hsts: {
maxAge: 15768000,
includeSubDomains: true,
preload: true
},
xframe: 'sameorigin'
}
}
const createRoutes = config => [
{
method: 'GET',
path: '/img/{param*}',
handler: {
directory: {
path: config.build.options.imgDir,
redirectToSlash: true,
index: true
}
},
options: routesOptions
},
{
method: 'GET',
path: '/language/{param*}',
handler: {
directory: {
path: path.join(__dirname, '../../language'),
redirectToSlash: true,
index: true
}
},
options: routesOptions
},
{
method: 'GET',
path: '/font/{param*}',
handler: {
directory: {
path: path.join(__dirname, '../../font'),
redirectToSlash: true,
index: true
}
},
options: routesOptions
},
{
method: 'GET',
path: '/sound/{param*}',
handler: {
directory: {
path: path.join(__dirname, '../../sound/'),
redirectToSlash: true,
index: true
}
},
options: routesOptions
},
{
method: 'GET',
path: '/emoji/{param*}',
handler: {
directory: {
path: path.join(__dirname, '../../emoji/'),
redirectToSlash: true,
index: true
}
},
options: routesOptions
},
{
method: 'GET',
path: '/memory-pow/{param*}',
handler: {
directory: {
path: path.join(__dirname, '../../memory-pow/'),
redirectToSlash: true,
index: true
}
},
options: routesOptions
},
{
method: 'GET',
path: '/getConfig',
handler: (request, h) => {
const response = {
config: {
...config
}
}
delete response.config.user.tls
delete response.config.build
return JSON.stringify(response)
},
options: routesOptions
}
]
module.exports = createRoutes

View File

@@ -0,0 +1,141 @@
const path = require('path')
const createCommonRoutes = require('./createCommonRoutes.js')
const createPrimaryRoutes = (config, plugins) => {
const routes = createCommonRoutes(config)
let myPlugins = plugins
const pluginFolders = {}
const routesOptions = {
security: {
hsts: {
maxAge: 15768000,
includeSubDomains: true,
preload: true
},
xframe: 'sameorigin'
}
}
plugins.reduce((obj, plugin) => {
obj[plugin.name] = plugin.folder
return obj
}, pluginFolders)
routes.push(
{
method: 'GET',
path: '/',
handler: (request, reply) => {
return reply.redirect('/app')
},
options: routesOptions
},
{
method: 'GET',
path: '/{path*}',
handler: (request, h) => {
const filePath = path.join(__dirname, '../../public/index.html')
const response = h.file(filePath, {
confine: true
})
response.header('Access-Control-Allow-Origin', request.info.host)
return response
},
options: routesOptions
},
{
method: 'GET',
path: '/getPlugins',
handler: (request, h) => {
return { plugins: myPlugins.map(p => p.name) }
},
options: routesOptions
},
{
method: 'GET',
path: '/build/{param*}',
handler: {
directory: {
path: config.build.options.outputDir,
redirectToSlash: true,
index: true
}
},
options: routesOptions
},
{
method: 'GET',
path: '/src/{param*}',
handler: {
directory: {
path: path.join(__dirname, '../../src'),
redirectToSlash: true,
index: true
}
},
options: routesOptions
},
{
method: 'GET',
path: '/plugin/{path*}',
handler: (request, h) => {
const plugin = request.params.path.split('/')[0]
const filePath = path.join(pluginFolders[plugin], '../', request.params.path)
const response = h.file(filePath, {
confine: false
})
response.header('Access-Control-Allow-Origin', request.info.host)
return response
},
options: routesOptions
},
{
method: 'GET',
path: '/plugin/404',
handler: (request, h) => {
const response = h.file(path.join(config.server.primary.page404))
response.header('Access-Control-Allow-Origin', request.info.host)
return response
},
options: routesOptions
},
{
method: 'GET',
path: '/qortal-components/plugin-mainjs-loader.html',
handler: (request, h) => {
const response = h.file(path.join(__dirname, '../../src/plugins/plugin-mainjs-loader.html'), {
confine: false
})
response.header('Access-Control-Allow-Origin', request.info.host)
return response
},
options: routesOptions
},
{
method: 'GET',
path: '/qortal-components/plugin-mainjs-loader.js',
handler: (request, h) => {
const file = path.join(config.build.options.outputDir, '/plugins/plugin-mainjs-loader.js')
const response = h.file(file, {
confine: false
})
response.header('Access-Control-Allow-Origin', request.info.host)
return response
},
options: routesOptions
},
)
return routes
}
module.exports = createPrimaryRoutes

24
core/server/server.js Normal file
View File

@@ -0,0 +1,24 @@
const ServerFactory = require('./ServerFactory.js')
const createPrimaryRoutes = require('./routes/createPrimaryRoutes.js')
const createServer = (config, plugins) => {
this.start = async function () {
const primaryServer = new ServerFactory(createPrimaryRoutes(config, plugins), config.user.server.primary.host, config.user.server.primary.port, config.user.tls.enabled ? config.user.tls.options : void 0)
primaryServer.startServer()
.then(server => {
console.log(`Qortal UI Server started at ${server.info.uri} and listening on ${server.info.address}`)
})
.catch(e => {
console.error(e)
})
}
return this
}
const serverExports = {
createServer
}
module.exports = serverExports