Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot identify directory #80

Open
goparklubanic opened this issue Jun 13, 2024 · 3 comments
Open

Cannot identify directory #80

goparklubanic opened this issue Jun 13, 2024 · 3 comments

Comments

@goparklubanic
Copy link

This plugin used in cordova project, then the app deployed into Android 11 phone. The www_root is newly created directory.
When a client open access the server, always got response:
INTERNAL ERRROR: serveFile(): given homeDir is not a directory.
So, what should be modified?

@ifigueroap
Copy link

I'm having the same issue, I don't know what to put in the www_root option...

@ifigueroap
Copy link

ifigueroap commented Oct 31, 2024

Finally, I found out that the relative paths are relative to the android/app/src/main/assets/www directory. This is hard-coded in the library. After putting my files in that location, the server worked with no issues.

If you are using Capacitor, the assets are copied into android/app/src/main/assets/public, and can't be accessed by the webserver, unless you use a full filesystem path (I guess). In my case it was better so simply copy the files to www.

@ifigueroap
Copy link

My code is something like this (in a Ionic/Angular + Capacitor app):

import { Component, OnInit } from '@angular/core';
import { File } from '@awesome-cordova-plugins/file/ngx';
import { InAppBrowser } from '@awesome-cordova-plugins/in-app-browser/ngx';
import { Platform } from '@ionic/angular';
import { IonButton, IonContent, IonHeader, IonTitle, IonToolbar } from '@ionic/angular/standalone';

declare var cordova: any;

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
  standalone: true,
  imports: [IonHeader, IonToolbar, IonTitle, IonContent, IonButton],
  providers: [InAppBrowser, File],
})
export class HomePage implements OnInit {
  localServerUrl: string = '';

  constructor(
    private iab: InAppBrowser,
    private platform: Platform,
    private file: File
  ) {}

  async ngOnInit() {
    await this.platform.ready();
    this.startLocalServer();
  }

  startLocalServer() {
    const options = {
      www_root: '', // Sets android/app/src/main/assets/www as webroot
      port: 8083,
      localhost_only: true, // Restrict to localhost
    };

    cordova.plugins.CorHttpd.startServer(
      options,
      (url: string) => {
        console.log('Local server started at:', url);
        this.localServerUrl = url;
        this.loadContent();
      },
      (error: any) => {
        console.error('Error starting server:', error);
      }
    );
  }

  loadContent() {
    const iframe: HTMLIFrameElement | null =
      document.querySelector('#iframe');
    if (iframe) {
      const srcUrl = `${this.localServerUrl}/index.htmll`; // will serve android/app/src/main/assets/www/index.html
      console.log(`Setting iframe src to ${srcUrl}`);
      iframe.src = srcUrl;
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants