@bitgenics/fab-static
Advanced tools
Comparing version 0.5.0 to 0.5.1
{ | ||
"name": "@bitgenics/fab-static", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "Front-end Application Bundle generator for (mostly) static applications.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -17,3 +17,3 @@ const HOUR_IN_SEC = 60 * 60 | ||
const STATIC_DIR_PATH = `/${config.staticDirPath}` | ||
const STATIC_DIR_PATH = `/${config.staticDirName}` | ||
@@ -34,4 +34,3 @@ let files = {} | ||
console.log({ files }) | ||
console.log({ htmls }) | ||
console.log({ files: Object.keys(files), htmls: Object.keys(htmls) }) | ||
@@ -55,3 +54,6 @@ const getPath = (url) => { | ||
const handleRedirectToAssets = async (req, _, next) => { | ||
const handleRedirectToAssets = async (req) => { | ||
//console.log('handleRedirectToAssets') | ||
//console.log(STATIC_DIR_PATH) | ||
//console.log(req.pathname) | ||
if (config.redirectToAssets && req.pathname.startsWith(STATIC_DIR_PATH)) { | ||
@@ -68,12 +70,11 @@ console.log('redirecting!') | ||
}) | ||
} else { | ||
return next() | ||
} | ||
} | ||
const handleFiles = async (req, _, next) => { | ||
const handleFiles = async (req) => { | ||
//console.log('handleFiles') | ||
if (files[req.pathname]) { | ||
const content = files[req.pathname] | ||
console.log({ content }) | ||
//console.log({ content }) | ||
const response = new Response(content.bytes, { | ||
@@ -83,12 +84,11 @@ status: 200, | ||
}) | ||
console.log({ response }) | ||
//console.log({ response }) | ||
return response | ||
} else { | ||
return next() | ||
} | ||
} | ||
const handleHTML = async (req, settings, next) => { | ||
const handleHTML = async (req, settings) => { | ||
//console.log('handleHTML') | ||
const pathname = req.pathname | ||
console.log(req.headers) | ||
//console.log(req.headers) | ||
const accepts_html = true //(req.headers.accept || '').match(/html/) | ||
@@ -99,4 +99,4 @@ // console.log({pathname, accepts_html}) | ||
: accepts_html | ||
? htmls['/_catch_all.html'] | ||
: null | ||
? htmls['/_catch_all.html'] | ||
: null | ||
@@ -111,9 +111,6 @@ if (html_handler) { | ||
const content = html_handler.renderToBuffer(data) | ||
const response = new Response(content, { | ||
return new Response(content, { | ||
status: 200, | ||
headers, | ||
}) | ||
return response | ||
} else { | ||
return next() | ||
} | ||
@@ -123,2 +120,3 @@ } | ||
const handle404 = async () => { | ||
//console.log('handle404') | ||
return new Response('Content not Found', { | ||
@@ -130,11 +128,6 @@ status: 404, | ||
const getRequestHandler = (handlers) => async (req, settings) => { | ||
let count = 0 | ||
const handle = async () => { | ||
console.log({ count }) | ||
return await handlers[count](req, settings, async () => { | ||
count++ | ||
return await handle() | ||
}) | ||
for (const handler of handlers) { | ||
const response = await handler(req, settings) | ||
if (typeof response !== 'undefined') return response | ||
} | ||
return await handle() | ||
} | ||
@@ -150,5 +143,6 @@ | ||
const render = async (req, settings) => { | ||
console.log({ req, settings }) | ||
//console.log({ req, settings }) | ||
try { | ||
req.pathname = getPath(req.url) | ||
console.log(req.pathname) | ||
return await handler(req, settings) | ||
@@ -155,0 +149,0 @@ } catch (e) { |
124479
18
467