Skip to content

Commit

Permalink
feat: general improvements (#181)
Browse files Browse the repository at this point in the history
* build(vscode): use typescript from the project

* fix(pages): do not use composable in middleware

* build(nuxt): do not generate shim

* build(nuxt): remove unused config values

* build(biome): add biome config

* build(nuxt): add database url as runtime config var
  • Loading branch information
arunanshub authored Feb 9, 2024
1 parent de4fb98 commit 4951929
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
18 changes: 18 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"formatter": {
"indentStyle": "space"
},
"javascript": {
"formatter": { "semicolons": "asNeeded", "quoteStyle": "single" }
}
}
9 changes: 4 additions & 5 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ export default defineNuxtConfig({
asyncContext: true,
headNext: true,
componentIslands: true,
inlineSSRStyles: true,
},
vue: { defineModel: true },

// Modules
modules: [
Expand Down Expand Up @@ -104,14 +102,15 @@ export default defineNuxtConfig({
'/': { swr: true },
'/quiz/**': { swr: true },
'/info/**': { static: true },
'/_api/**': { proxy: '/api/**' },
},
runtimeConfig: {
databaseUrl: process.env.DATABASE_URL,
},

// Development
// Development
devtools: { enabled: true },
typescript: {
strict: true,
shim: false,
tsConfig: {
compilerOptions: {
types: ['@types/node'],
Expand Down
12 changes: 10 additions & 2 deletions src/pages/index/quiz/[section].vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,16 @@ definePageMeta({
scrollToTop: false,
middleware: async (to) => {
const currentSection = to.params.section as string
const { sections } = await useFetchSection()
const isSectionValid = !!sections.value?.find(
// XXX: nuxt says that you cannot use a composable outside of setup or
// custom composable. For the same reason, we cannot use useFetchSection()
// in the middleware. We will resort to direct `$fetch` call.
let sections
try {
sections = await $fetch('/api/sections')
} catch (error) {
return abortNavigation({ statusCode: 404, message: 'No sections found' })
}
const isSectionValid = !!sections.find(
(s) => s.msgid === currentSection
)
Expand Down

0 comments on commit 4951929

Please sign in to comment.