Web Server

Contents

This plugin allows you to start a local dynamic content web server for android and iOS devices.

https://github.com/bykof/cordova-plugin-webserver.git

Ionic Web Server插件的安装(Installation)

ionic cordova plugin add cordova-plugin-webserver npm install @ionic-native/web-server

Ionic Web Server插件支持的平台(Supported Platforms)

  • Android
  • iOS

Ionic Web Server插件的用法(Usage)

import { WebServer } from '@ionic-native/web-server';


constructor(private webServer: WebServer) { }

...

this.webServer.onRequest().subscribe(data => {
  console.log(data);
  const res: Response = {
    status: 200,
    body: '',
    headers: {
      'Content-Type': 'text/html'
    }
  };

  this.webServer.sendResponse(data.requestId, res)
    .catch((error: any) => console.error(error));
});

this.webServer.start(80)
  .catch((error: any) => console.error(error));