I am currently working on an application built with Ionic and socket IO. In the app.module.ts file, the socket import requires a configuration for the URL and options. The issue is that this configuration is hardcoded, and I would prefer to have it dynamically fetched from a form or stored data. I want to avoid having to redeploy the application every time there is a change in the IP address or server port, and I also do not want to rely on a DNS link. Can anyone provide guidance on how to achieve this?
My current setup includes Ionic 5.4.5, Cordova 9.0.0, and deployment on IOS 12.4.
Below is a snippet of my app.module.ts file:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { ErrorHandler } from '@angular/core';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HttpClientModule } from '@angular/common/http';
import { SocketIoModule, SocketIoConfig } from 'ng-socket-io';
const config: SocketIoConfig = { url: 'http://192.168.0.17:3001', options: {} };
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [
BrowserModule,
IonicModule.forRoot(),
AppRoutingModule,
HttpClientModule,
SocketIoModule.forRoot(config),
],
providers: [
StatusBar,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
bootstrap: [AppComponent]
})
export class AppModule { }
Any insights or responses would be greatly appreciated. Thank you.