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 type { Authenticators } from '@adonisjs/auth/types'
4+ import env from '#start/env'
5+ import app from '@adonisjs/core/services/app'
6+
7+ const APP_URL = new URL ( '/' , env . get ( 'APP_URL' ) )
8+
9+ /**
10+ * Auth middleware is used authenticate HTTP requests and deny
11+ * access to unauthenticated users.
12+ */
13+ export default class AppUrlMiddleware {
14+ async handle ( ctx : HttpContext , next : NextFn ) {
15+ if ( app . inProduction ) {
16+ return next ( )
17+ }
18+
19+ const requestUrl = ctx . request . url ( true )
20+ if ( ctx . request . method ( ) === 'GET' && ctx . request . host ( ) !== APP_URL . host ) {
21+ const correctedUrl = new URL ( requestUrl , APP_URL . toString ( ) ) . toString ( )
22+
23+ ctx . response . redirect ( ) . toPath ( correctedUrl )
24+ }
25+
26+ return next ( )
27+ }
28+ }
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