MCPcopy Create free account
hub / github.com/langgenius/dify / createDevProxyApp

Function createDevProxyApp

packages/dev-proxy/src/server.ts:239–282  ·  view source on GitHub ↗
(options: CreateDevProxyAppOptions)

Source from the content-addressed store, hash-verified

237}
238
239export const createDevProxyApp = (options: CreateDevProxyAppOptions) => {
240 const app = new HonoApp()
241 const fetchImpl = options.fetchImpl || globalThis.fetch
242 const logger = options.logger || console
243 const allowedOrigins = options.cors?.allowedOrigins || 'local'
244
245 app.onError((error, context) => {
246 logger.error('[dev-proxy]', error)
247
248 const headers = new Headers()
249 applyCorsHeaders(headers, context.req.header('origin'), allowedOrigins)
250
251 return new Response('Upstream proxy request failed.', {
252 status: 502,
253 headers,
254 })
255 })
256
257 app.use('*', async (context, next) => {
258 if (context.req.method === 'OPTIONS') {
259 const headers = new Headers()
260 applyCorsHeaders(headers, context.req.header('origin'), allowedOrigins)
261 headers.set('Access-Control-Allow-Methods', ALLOW_METHODS)
262 headers.set(
263 'Access-Control-Allow-Headers',
264 context.req.header('Access-Control-Request-Headers') || DEFAULT_ALLOW_HEADERS,
265 )
266 if (context.req.header('Access-Control-Request-Private-Network') === 'true')
267 headers.set('Access-Control-Allow-Private-Network', 'true')
268
269 return new Response(null, {
270 status: 204,
271 headers,
272 })
273 }
274
275 await next()
276 applyCorsHeaders(context.res.headers, context.req.header('origin'), allowedOrigins)
277 })
278
279 registerProxyRoutes(app, options.routes, fetchImpl, allowedOrigins)
280
281 return app
282}

Callers 3

startDevProxyServerFunction · 0.90
updateConfigFunction · 0.90
server.spec.tsFile · 0.90

Calls 8

applyCorsHeadersFunction · 0.85
nextFunction · 0.85
registerProxyRoutesFunction · 0.85
headerMethod · 0.80
useMethod · 0.80
onErrorMethod · 0.45
errorMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected