change default port, use for getting assets

This commit is contained in:
hazycora 2023-12-21 10:03:32 -06:00
parent 996b596f96
commit 0c423c11da
No known key found for this signature in database
GPG key ID: 215AF1F81F86940E
3 changed files with 10 additions and 13 deletions

View file

@ -1,6 +1,5 @@
@import url('/assets/DMSans/style.css');
body { body {
font-family: 'DM Sans', sans-serif; font-family: 'DM Sans', Arial, Helvetica, sans-serif;
margin: 0; margin: 0;
} }
div { div {

View file

@ -1,7 +1,5 @@
import puppeteer from 'puppeteer' import puppeteer from 'puppeteer'
import fs from 'node:fs' import { BASE_URL } from '../server.js'
const style = fs.readFileSync('./assets/style.css', 'utf8')
const browser = await puppeteer.launch({ const browser = await puppeteer.launch({
defaultViewport: { defaultViewport: {
@ -60,13 +58,11 @@ export async function renderPage(html) {
} }
export default async function (html, options = {}) { export default async function (html, options = {}) {
const fullHtml = `<link rel="stylesheet" href="${BASE_URL}/assets/style.css">
<link rel="stylesheet" href="${BASE_URL}/assets/DMSans/style.css">
${html}`
if (options.format == 'html') { if (options.format == 'html') {
return await renderHtml(html) return fullHtml
} }
return renderPage(`<style>${style}</style>${html}`) return await renderPage(fullHtml)
}
export async function renderHtml(html) {
const styleNow = await fs.promises.readFile('./assets/style.css', 'utf8')
return `<style>${styleNow}</style>${html}`
} }

View file

@ -263,7 +263,9 @@ app.get('/:owner/:repo/pulls/:num', async function (req, res) {
res.send(await render(html, app.locals.options)) res.send(await render(html, app.locals.options))
}) })
const [port, host] = [process.env.PORT ?? 9054, process.env.HOST ?? '127.0.0.1'] const [port, host] = [process.env.PORT ?? 8000, process.env.HOST ?? '0.0.0.0']
export const BASE_URL = `http://${host}:${port}`
app.listen(port, host, () => { app.listen(port, host, () => {
console.log(`Listening on http://${host}:${port}`) console.log(`Listening on http://${host}:${port}`)