Skip to content

Commit

Permalink
Merge branch 'master' into chore/format
Browse files Browse the repository at this point in the history
  • Loading branch information
nobkd authored Aug 30, 2024
2 parents e80b4a4 + dcc3d24 commit 31b8f87
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 @@ -137,11 +137,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 @@ -40,15 +40,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 31b8f87

Please sign in to comment.