Skip to content

Commit

Permalink
fix(demo): reference files from root add specifier
Browse files Browse the repository at this point in the history
  • Loading branch information
tobua committed Feb 3, 2024
1 parent 09a01d7 commit 770ab6b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion demo/api/serverless/[lang].ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import type { VercelRequest, VercelResponse } from '@vercel/node'
import { Language } from 'epic-language'
import { translate } from 'epic-language/function'
import englishSheet from './../en.json'
import { promises as fs } from 'fs'
import { it } from 'avait'

export default async function handler(request: VercelRequest, response: VercelResponse) {
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 { 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
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(`./../translations/${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
4 changes: 3 additions & 1 deletion demo/api/static/serverless/[lang].ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ 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`))
const { error, value: sheet } = await it(
import(`./../translations/${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
4 changes: 2 additions & 2 deletions demo/vercel.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"functions": {
"api/static/serverless/[lang].ts": {
"includeFiles": "./api/static/translations/*.json"
"includeFiles": "demo/api/static/translations/*.json"
},
"api/static/edge/[lang].ts": {
"includeFiles": "./api/static/translations/*.json"
"includeFiles": "demo/api/static/translations/*.json"
}
}
}

0 comments on commit 770ab6b

Please sign in to comment.