File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ ' eurosky-portal ' : patch
3+ ---
4+
5+ Add development middleware to ensure correct host for requests
Original file line number Diff line number Diff line change 1+ import type { HttpContext } from '@adonisjs/core/http'
2+ import type { NextFn } from '@adonisjs/core/types/http'
3+ import env from '#start/env'
4+ import app from '@adonisjs/core/services/app'
5+
6+ const APP_URL = new URL ( '/' , env . get ( 'APP_URL' ) )
7+
8+ /**
9+ * Auth middleware is used authenticate HTTP requests and deny
10+ * access to unauthenticated users.
11+ */
12+ export default class AppUrlMiddleware {
13+ async handle ( ctx : HttpContext , next : NextFn ) {
14+ if ( app . inProduction ) {
15+ return next ( )
16+ }
17+
18+ const requestUrl = ctx . request . url ( true )
19+ if ( ctx . request . method ( ) === 'GET' && ctx . request . host ( ) !== APP_URL . host ) {
20+ const correctedUrl = new URL ( requestUrl , APP_URL . toString ( ) ) . toString ( )
21+
22+ ctx . response . redirect ( ) . toPath ( correctedUrl )
23+ }
24+
25+ return next ( )
26+ }
27+ }
Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ router.use([
4040 ( ) => import ( '@adonisjs/core/bodyparser_middleware' ) ,
4141 ( ) => import ( '@adonisjs/session/session_middleware' ) ,
4242 ( ) => import ( '@adonisjs/shield/shield_middleware' ) ,
43+ ( ) => import ( '#middleware/app_url_middleware' ) ,
4344 ( ) => import ( '@adonisjs/auth/initialize_auth_middleware' ) ,
4445 ( ) => import ( '#middleware/silent_auth_middleware' ) ,
4546 ( ) => import ( '@thisismissem/adonisjs-atproto-oauth/initialize_atproto_auth_middleware' ) ,
You can’t perform that action at this time.
0 commit comments