import EnsService from '../../../services/EnsService' ; import NftService from '../../../services/NftService' ; import View from '@ioc:Adonis/Core/View' ; export default class LandingController { private mainHostingDomain = 'eth.xyz' ; private ensService = new EnsService ( ) ; public async index ( { request , params , response } ) { let domainBeingAccessed = '' ; let domainToLookup = '' ; if ( request . header ( 'Proxy-Host' ) !== undefined && request . header ( 'Proxy-Host' ) !== '' ) { domainBeingAccessed = request . header ( 'Proxy-Host' ) ; } else { domainBeingAccessed = request . headers ( ) . host . split ( ':' ) . shift ( ) ; } if ( domainBeingAccessed === this . mainHostingDomain || domainBeingAccessed === 'localhost' ) { if ( typeof params . domainAsPath === 'string' ) { domainToLookup = params . domainAsPath ; domainBeingAccessed = this . mainHostingDomain + '/' + domainToLookup ; } else { return await View . render ( 'landing_about' ) ; } } else if ( domainBeingAccessed . indexOf ( this . mainHostingDomain ) !== - 1 ) { let domainBeingAccessedParts = domainBeingAccessed . split ( '.' ) ; if ( domainBeingAccessedParts . length > 3 ) { return response . redirect ( ) . status ( 302 ) . toPath ( 'https://' + domainBeingAccessedParts . slice ( - 3 ) . join ( '.' ) ) ; } domainToLookup = domainBeingAccessed . replace ( `.${ this . mainHostingDomain }` , '' ) + '.eth' ; } else { domainToLookup = domainBeingAccessed ; } return await View . render ( 'landing_index' , { domainToLookup : domainToLookup , domainBeingAccessed : domainBeingAccessed , } ) ; } public async textRecords ( { params } ) { const records = await this . ensService . getTextRecords ( params . domain ) ; return { success : records !== null , data : records , } ; } public async nfts ( { params } ) { const nftService = new NftService ( ) ; const nfts = await nftService . getNfts ( params . ethWallet ) ; return { success : nfts !== null , data : nfts , } ; } public async 404 ( { response } ) { response . status ( 404 ) ; return await View . render ( 'errors/not-found' ) ; } }