Skip to content

Commit

Permalink
fix(demo): assume include is relative to function path
Browse files Browse the repository at this point in the history
  • Loading branch information
tobua committed Feb 3, 2024
1 parent 770ab6b commit c5ae16b
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 7 deletions.
2 changes: 1 addition & 1 deletion demo/api/serverless/[lang].ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default async function handler(request: VercelRequest, response: VercelRe
const language = request.query.lang as Language
if (!(language in Language))
return response.status(500).json({ error: `Missing language "${language}"` })
const englishSheet = JSON.parse(await fs.readFile(process.cwd() + './../en.json', 'utf8'))
const englishSheet = JSON.parse(await fs.readFile(process.cwd() + './en.json', 'utf8'))
const { error, value: sheet } = await it(translate(JSON.stringify(englishSheet), language))
if (error)
return response.status(500).json({ error: `Translation for language "${language}" failed!` })
Expand Down
1 change: 1 addition & 0 deletions demo/api/serverless/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "title": "My Title", "description": "This is the description." }
2 changes: 1 addition & 1 deletion demo/api/static/edge/[lang].ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export async function GET(request: Request) {
const searchParams = new URL(request.url).searchParams
const language = searchParams.get('lang') ?? ''
if (!(language in Language)) return new Response(`Missing language "${language}"`)
const { error, value: sheet } = await it(import(`./../translations/${language}.json`))
const { error, value: sheet } = await it(import(`./${language}.json`))
console.log(error, sheet)
if (error) return new Response(`Sheet for language "${language}" not found!`)
return new Response(JSON.stringify(sheet), {
Expand Down
6 changes: 6 additions & 0 deletions demo/api/static/edge/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"title": "My Title",
"description": "This is the description.",
"counter": "Count: {}",
"time": "Current time in {2} is {1}"
}
6 changes: 6 additions & 0 deletions demo/api/static/edge/es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"title": "Mi título",
"description": "Esta es la descripción.",
"counter": "Cuenta: {}",
"time": "La hora actual en {2} es {1}"
}
6 changes: 6 additions & 0 deletions demo/api/static/edge/zh.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"title": "我的标题",
"description": "这是说明。",
"counter": "计数: {}",
"time": "{2}时的当前时间是{1}"
}
4 changes: 1 addition & 3 deletions demo/api/static/serverless/[lang].ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ export default async function handler(request: VercelRequest, response: VercelRe
const language = request.query.lang as Language
if (!(language in Language))
return response.status(500).json({ error: `Missing language "${language}"` })
const { error, value: sheet } = await it(
import(`./../translations/${language}.json`, { with: { type: 'json' } }),
)
const { error, value: sheet } = await it(import(`./${language}.json`, { with: { type: 'json' } }))
console.log(error, sheet)
if (error)
return response.status(500).json({ error: `Sheet for language "${language}" not found!` })
Expand Down
6 changes: 6 additions & 0 deletions demo/api/static/serverless/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"title": "My Title",
"description": "This is the description.",
"counter": "Count: {}",
"time": "Current time in {2} is {1}"
}
6 changes: 6 additions & 0 deletions demo/api/static/serverless/es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"title": "Mi título",
"description": "Esta es la descripción.",
"counter": "Cuenta: {}",
"time": "La hora actual en {2} es {1}"
}
6 changes: 6 additions & 0 deletions demo/api/static/serverless/zh.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"title": "我的标题",
"description": "这是说明。",
"counter": "计数: {}",
"time": "{2}时的当前时间是{1}"
}
8 changes: 6 additions & 2 deletions demo/vercel.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{
"$schema": "https://openapi.vercel.sh/vercel.json",
"functions": {
"api/static/serverless/[lang].ts": {
"includeFiles": "demo/api/static/translations/*.json"
"includeFiles": "*.json"
},
"api/static/edge/[lang].ts": {
"includeFiles": "demo/api/static/translations/*.json"
"includeFiles": "*.json"
},
"api/serverless/[lang].ts": {
"includeFiles": "*.json"
}
}
}

0 comments on commit c5ae16b

Please sign in to comment.