elysiajs / eden

Fully type-safe Elysia client
MIT License
173 stars 41 forks source link

Type Error: 'app' is a type of unknown #53

Closed ghost closed 9 months ago

ghost commented 9 months ago

I get a typerror when accessing routes by their name image

here's my code

// app.ts
import { Elysia } from 'elysia'
import { helmet } from 'elysia-helmet'
import { rateLimit } from 'elysia-rate-limit'
import swagger from '@elysiajs/swagger'
import cors from '@elysiajs/cors'
import user from './Controllers/user'
import blog from './Controllers/blog'

const app = new Elysia()

app
    .onError(({ code, error, path }) => {
        if (code === 'NOT_FOUND') {
            return { err: `Couldn't find what you was looking for` }
        }
        if (code === 'INTERNAL_SERVER_ERROR') {
            return { err: `Something went wrong on our server, We'll try to fix it ASAP!` }
        }
        console.error(`Error occurred on path ${path} Error: ${error}, ${code}`)
    })
    .use(helmet())
    .use(swagger())
    .use(cors({ origin: process.env.DOMAIN, credentials: true }))
    .use(
        rateLimit({
            duration: 300000,
            max: 5200,
            responseCode: 420,
            responseMessage: 'Our server needs a 5 min coffee break'
        })
    )
    .use(user)
    .use(blog)
    .onResponse(() => {
        console.log(`response speed was: ${performance.now()}ms`)
    })
    .listen(process.env.PORT || 5000)

console.log(`Server running on ${app.server?.url}`)

export type App = typeof app
// +page.server.ts
import type { PageLoad } from './$types'
import {edenTreaty} from '@elysiajs/eden'
import type { App } from '../../../../../backend/src/app.ts'
const app = edenTreaty<App>(`http://backend:3000`)

export const load = (async ({ url }) => {

    const res = app.profile.tech

    const user = res.data.user
    const state = res.data.state
    console.log(res.data)

    return { user, state }
}) satisfies PageLoad