4
1
mirror of https://github.com/Qortal/qortal-ui.git synced 2025-02-11 17:55:51 +00:00
qortal-ui/core/server/ServerFactory.js

35 lines
595 B
JavaScript
Raw Permalink Normal View History

2021-12-25 14:39:47 +01:00
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
})
2021-12-25 14:39:47 +01:00
this.startServer = async () => {
try {
await this.server.register([Inert])
2021-12-25 14:39:47 +01:00
this.server.route(routes)
2021-12-25 14:39:47 +01:00
await this.server.start()
2021-12-25 14:39:47 +01:00
delete this.startServer
return this.server
} catch (e) {
console.error(e)
throw e
}
}
2021-12-25 14:39:47 +01:00
}
module.exports = serverFactory