-
Hey everyone! How I can use it and bind to Modern.js middlewares? I see two types middleware:
To Modern.js ecosystem? Thank you so much in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Thanks for your feedback, Using You can try to code it like this: import { defineServerConfig, type MiddlewareHandler } from '@modern-js/server-runtime';
const googleAuthHandler: MiddlewareHandler = googleAuth({
client_id: Bun.env.GOOGLE_ID,
client_secret: Bun.env.GOOGLE_SECRET,
scope: ['openid', 'email', 'profile'],
});
const googleRouteHandler: MiddlewareHandler = (c) => {
const token = c.get('token')
const grantedScopes = c.get('granted-scopes')
const user = c.get('user-google')
return c.json({
token,
grantedScopes,
user,
})
})
export default defineServerConfig({
middlewares: [
{
name: 'google-auth',
handler: googleAuthHandler,
},
{
name: 'google-route-handler',
path: '/google',
handler: googleRouteHandler,
},
],
}); If you have any questions, feel free to comment. We just released the Hono based Middleware recently :) @keepview cc And wee do not expose the hono instance For now, it seems that the Hono middleware can meet most demand. If it doesn’t, please let us know. |
Beta Was this translation helpful? Give feedback.
-
I will check, Thank you! |
Beta Was this translation helpful? Give feedback.
Thanks for your feedback, Using
MiddlewareHandler
, theUnstableMiddleware
is deprecated.https://modernjs.dev/zh/guides/advanced-features/web-server.html#middleware
You can try to code it like this: