-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated deps `backend` major overhaul: + structuring + `srvx` for universal serving + a damn good providers pattern that supports workerd Added openApi capability to `backend`
- Loading branch information
Showing
34 changed files
with
3,064 additions
and
3,237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,3 +50,6 @@ yarn-error.log* | |
|
||
# sst | ||
.sst | ||
|
||
# pnpm have a bug with tsx that creates the `tsx-0` folder everywhere | ||
tsx-0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { appFactory } from '~/helpers/factory' | ||
|
||
export const apiRouteApp = appFactory.createApp() | ||
.get('', async c => c.text('OK')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,26 @@ | ||
import { appFactory } from '~/factory' | ||
import { authApp } from './auth/app' | ||
import { greetRouteApp } from './greet' | ||
import { helloRouteApp } from './hello' | ||
import { appFactory } from '~/helpers/factory' | ||
import { apiRouteApp } from './$$' | ||
import { authApp } from './auth/$' | ||
import { dummyApp } from './dummy/$' | ||
|
||
export const apiApp = appFactory.createApp() | ||
// Simple health check route | ||
.route('', apiRouteApp) | ||
|
||
// Auth app - you'll need to setup Kinde environment variables. | ||
.route('/auth', authApp) | ||
|
||
// Simple health check route | ||
.route('/hello', helloRouteApp) | ||
|
||
// Simple greet route for arktype input validation demo | ||
.route('/greet', greetRouteApp) | ||
// A dummy app for some demos | ||
.route('/dummy', dummyApp) | ||
|
||
// ### This block contains the sample code for streaming APIs, | ||
// import type { TypedResponse } from 'hono' | ||
// import { streamText } from 'hono/streaming' | ||
|
||
// Do note that SST doesn't support Live Development for Lambda streaming API yet: https://github.com/sst/ion/issues/63 | ||
// Do note that SST doesn't support Live Development for Lambda streaming API yet: https://sst.dev/docs/component/aws/function/#streaming | ||
|
||
// For RPC to know the type of streamed endpoints you could manually cast it with TypedResponse 👌 | ||
// .get('/helloStream', c => streamText(c, async (stream) => { | ||
// await stream.writeln('Hello from Hono `/api/helloStream`!') | ||
// }) as Response & TypedResponse<'Hello from Hono `/api/helloStream`!'>) | ||
// ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { appFactory } from '~/helpers/factory' | ||
import { authRoutesApp } from './$.routes' | ||
|
||
export const authApp = appFactory.createApp() | ||
.route('', authRoutesApp) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { appFactory } from '~/helpers/factory' | ||
import { dummyGreetRouteApp } from './greet' | ||
import { dummyHelloRouteApp } from './hello' | ||
|
||
export const dummyApp = appFactory.createApp() | ||
.route('/hello', dummyHelloRouteApp) | ||
|
||
.route('/greet', dummyGreetRouteApp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { type } from 'arktype' | ||
import { describeRoute } from 'hono-openapi' | ||
import { resolver } from 'hono-openapi/arktype' | ||
import { customArktypeValidator } from '~/helpers/arktype' | ||
import { appFactory } from '~/helpers/factory' | ||
|
||
export const dummyGreetRouteApp = appFactory.createApp() | ||
.get( | ||
'', | ||
describeRoute({ | ||
description: 'Say hello to a user', | ||
responses: { | ||
200: { | ||
description: 'Successful response', | ||
content: { | ||
'text/plain': { schema: resolver( | ||
type('string'), | ||
) }, | ||
}, | ||
}, | ||
}, | ||
}), | ||
customArktypeValidator('query', type({ | ||
name: 'string>0', | ||
})), | ||
async (c) => { | ||
const { name } = c.req.valid('query') | ||
return c.text(`Hello ${name}!`) | ||
}, | ||
) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { appFactory } from '~/helpers/factory' | ||
import { getHelloMessage } from './hello.helper' | ||
|
||
export const dummyHelloRouteApp = appFactory.createApp() | ||
.get('', async c => c.text(getHelloMessage())) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { cors } from 'hono/cors' | ||
import { logger as loggerMiddleware } from 'hono/logger' | ||
import { env } from 'std-env' | ||
import { errorHandler } from '~/helpers/error' | ||
import { appFactory, triggerFactory } from '~/helpers/factory' | ||
import { cookieSession } from '~/middlewares/session' | ||
import { apiApp } from './api/$' | ||
import { logger } from './helpers/logger' | ||
import { providersInit } from './providers' | ||
|
||
export const app = appFactory.createApp() | ||
// Initialize providers | ||
.use(providersInit) | ||
|
||
// Register global not found handler | ||
.notFound(c => c.text('four-o-four', 404)) | ||
|
||
// Register global error handler | ||
.onError(errorHandler) | ||
|
||
// Request logging middleware | ||
.use(loggerMiddleware(logger.log)) | ||
|
||
// Register trigger routes, after the logging middleware but before the request-based middlewares | ||
.route('/', triggerFactory.honoApp) | ||
|
||
// CORS middleware | ||
.use(cors({ | ||
origin: [env.FRONTEND_URL!], | ||
credentials: true, | ||
})) | ||
|
||
// Session management middleware, configure and see all available managers in `src/middlewares/session.ts` | ||
.use(await cookieSession()) | ||
|
||
// Register API routes | ||
.route('/api', apiApp) |
2 changes: 1 addition & 1 deletion
2
apps/backend/src/middlewares/arktype.ts → apps/backend/src/helpers/arktype.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.