Skip to content

Commit

Permalink
feat: add config deps & add naily.config.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
nailiable committed Nov 7, 2024
1 parent d6060c5 commit 3cb4844
Show file tree
Hide file tree
Showing 12 changed files with 3,302 additions and 2,199 deletions.
4 changes: 2 additions & 2 deletions backend/main.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// backend/main.ts
/// <reference types="vite/client" />

import { NodeHttpAdapter } from '@nailyjs/backend/node-adapter'
import { RpcBootstrap } from '@nailyjs/rpc'
import './welcome-server'

// You must export `app` for the plugin to work.
// you also can configure your export key in the plugin options.
export const app = new RpcBootstrap(new NodeHttpAdapter())
export const app = new RpcBootstrap()
.setBaseURL('/rpc')

// It will be called when environment is production mode
if (import.meta.env.PROD)
Expand Down
20 changes: 20 additions & 0 deletions backend/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export interface AppConfiguration {
// Custom your configuration
}

declare global {
namespace Naily {
namespace Configuration {
interface NailyUserConfig {
app?: AppConfiguration
}

interface NailyUserIntelliSense {
/* Custom `@Value` Decorator intellisense */
app?: AppConfiguration
}
}
}
}

export {}
4 changes: 2 additions & 2 deletions backend/welcome-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export class WelcomeServerImpl implements WelcomeServer {
sayHello() {
this.toggle = !this.toggle
return this.toggle
? 'Hello, world! Click me to refetch?'
: 'Hello, vitesse! Click me to refetch.'
? 'Hello, world! Click me to refetch~?'
: 'Hello, vitesse! Click me to refetch.~'
}

sayGoodbye() {
Expand Down
14 changes: 2 additions & 12 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
// @ts-check
import antfu from '@antfu/eslint-config'
import naily from '@nailyjs/eslint'

export default antfu(
{
unocss: true,
formatters: true,
rules: {
'ts/no-redeclare': 'off',
'ts/method-signature-style': 'off',
'ts/no-namespace': 'off',
},
},
)
export default naily()
2 changes: 1 addition & 1 deletion frontend/apis/welcome.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useRequest } from '../utils/request'
import { WelcomeServer } from '~common/welcome-protocol'
import { useRequest } from '../utils/request'

export function useWelcomeServer() {
const client = useRequest()
Expand Down
4 changes: 2 additions & 2 deletions frontend/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ViteSSG } from 'vite-ssg'
import type { UserModule } from './types'
import { setupLayouts } from 'virtual:generated-layouts'

import { ViteSSG } from 'vite-ssg'
import { routes } from 'vue-router/auto-routes'
import App from './App.vue'
import type { UserModule } from './types'

import '@unocss/reset/tailwind.css'
import './styles/main.css'
Expand Down
1 change: 1 addition & 0 deletions frontend/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function fetchTips() {
welcome.request()
.sayHello()
.then(str => tips.value = str)
.catch(() => tips.value = 'Failed to fetch tips')
}
fetchTips()
</script>
Expand Down
8 changes: 6 additions & 2 deletions frontend/utils/request.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { createRpcClient } from '@nailyjs/rpc/axios'
import { createAxiosClient } from '@nailyjs/rpc/axios'
import { isClient } from '@vueuse/core'

export function useRequest() {
return createRpcClient(import.meta.env.PROD ? 'http://localhost:1000/rpc' : '/rpc')
return createAxiosClient({
urlOrAxiosInstance: import.meta.env.PROD ? 'http://localhost:1000/rpc' : '/rpc',
ssr: !isClient,
})
}
5 changes: 5 additions & 0 deletions naily.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from '@nailyjs/config'

export default defineConfig({
naily: {},
})
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
"@antfu/eslint-config": "^2.27.1",
"@iconify-json/carbon": "^1.1.37",
"@intlify/unplugin-vue-i18n": "^4.0.0",
"@nailyjs/backend": "^1.0.14",
"@nailyjs/ioc": "^1.0.14",
"@nailyjs/rpc": "^1.0.14",
"@nailyjs/backend": "^2.0.5",
"@nailyjs/config": "^2.0.4",
"@nailyjs/eslint": "^2.0.5",
"@nailyjs/ioc": "^2.0.3",
"@nailyjs/rpc": "^2.0.5",
"@shikijs/markdown-it": "^1.14.1",
"@types/markdown-it-link-attributes": "^3.0.5",
"@types/nprogress": "^0.2.3",
Expand All @@ -62,7 +64,7 @@
"typescript": "^5.5.4",
"unocss": "^0.62.2",
"unplugin-auto-import": "^0.18.2",
"unplugin-rpc": "^1.0.14",
"unplugin-rpc": "^2.0.6",
"unplugin-vue-components": "^0.27.4",
"unplugin-vue-macros": "^2.11.6",
"unplugin-vue-markdown": "^0.26.2",
Expand Down
Loading

0 comments on commit 3cb4844

Please sign in to comment.