pzp-hub/lib/index.js

39 lines
999 B
JavaScript

import { createRequire } from 'node:module'
import path from 'node:path'
import homepageHTML from './homepage.js'
const require = createRequire(import.meta.url)
const __dirname = path.dirname(new URL(import.meta.url).pathname)
const fastify = require('fastify')
const fastifyView = require('@fastify/view')
const fastifyStatic = require('@fastify/static')
const ejs = require('ejs')
const logger = require('./logger.cjs')
const startPeer = require('./peer.cjs')
const staticsPath = path.join(__dirname, 'public')
const viewsPath = path.join(__dirname, 'views')
const app = fastify({ logger })
app.register(fastifyView, { engine: { ejs }, root: viewsPath })
app.register(fastifyStatic, { root: staticsPath })
app.get('/', (req, reply) => {
reply.view('homepage.ejs', { markdown: homepageHTML })
})
app.get('/invite', (req, reply) => {
reply.view('invite.ejs')
})
app.listen({ port: 3000 }, (err, address) => {
if (err) {
app.log.error(err)
process.exit(1)
}
startPeer()
})