Skip to content

Commit

Permalink
Merge pull request #334 from nobkd/fix/unknown-mime
Browse files Browse the repository at this point in the history
fix: handle unknown mime
  • Loading branch information
tipiirai authored Aug 30, 2024
2 parents c4f8e32 + c72483c commit dcc3d24
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 deletions packages/nuekit/src/browser/view-transitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,12 @@ export function onclick(root, fn) {
const el = e.target.closest('[href]')
const path = el?.getAttribute('href')
const target = el?.getAttribute('target')
const name = path?.split('/')?.pop()?.split(/[#?]/)?.shift()

// event ignore
if (e.defaultPrevented || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey ||
!path || path[0] == '#' || path.includes('//') || path.startsWith('mailto:') ||
target == '_blank') return
!path || path[0] == '#' || path?.includes('//') || path?.startsWith('mailto:') ||
(name?.includes('.') && !name?.endsWith('.html')) || target == '_blank') return

// all good
if (path != location.pathname) fn(path)
Expand Down
9 changes: 6 additions & 3 deletions packages/nuekit/src/nueserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,18 @@ export function createServer(root, callback) {
}

let [ url, _ ] = req.url.split('?')
const ext = extname(url).slice(1)
let ext = extname(url).slice(1)

if (!ext) url = join(url, 'index.html')
if (!ext) {
url = join(url, 'index.html')
ext = 'html'
}

try {
const { code, path } = !ext || ext == 'html' ? await callback(url, _) : { path: url }
if (!path) throw { errno: -2 }
const buffer = await fs.readFile(join(root, path))
res.writeHead(code || 200, { 'content-type': TYPES[ext] || TYPES.html })
res.writeHead(code || 200, { 'content-type': TYPES[ext] })
res.end(buffer)

} catch(e) {
Expand Down

0 comments on commit dcc3d24

Please sign in to comment.