-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kj
committed
Dec 8, 2023
1 parent
c4876b5
commit f56c9ab
Showing
4 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { join } from 'path' | ||
import { pathToFileURL } from 'url' | ||
|
||
export default async function GetPreflight({ basePath = '' }) { | ||
try { | ||
const pathToPreflight = pathToFileURL(join(basePath, 'preflight.mjs')).href | ||
const { default: preflight } = await import(pathToPreflight) | ||
return preflight | ||
} | ||
catch (error) { | ||
return {} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import path from 'path' | ||
import test from 'tape' | ||
import url from 'url' | ||
import getPreflight from '../src/http/any-catchall/_get-preflight.mjs' | ||
const __dirname = path.dirname(url.fileURLToPath(import.meta.url)) | ||
|
||
test.only('getPreflight', async t => { | ||
t.plan(1) | ||
const basePath = path.join(__dirname, 'mock-preflight', 'app') | ||
const expected = { | ||
title: 'About', | ||
account: { | ||
username: 'Bob Syouruncle', | ||
id: '23jk24h24' | ||
} | ||
} | ||
const preflight = await getPreflight({ basePath }) | ||
t.deepEqual(expected, preflight({ req: { path: '/about' } }), 'Got preflight') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export default function Preflight({ req }) { | ||
return { | ||
title: getPageTitle(req.path), | ||
account: { | ||
username: 'Bob Syouruncle', | ||
id: '23jk24h24' | ||
} | ||
} | ||
} | ||
|
||
function getPageTitle(path) { | ||
const titleMap = { | ||
'/': 'Home', | ||
'/about': 'About', | ||
'/account': 'My Account' | ||
} | ||
|
||
return titleMap[path] || 'My App Name' | ||
} |