Domanda

I have been able to run the dart-by-example http-server Hello web server. The websocket uses port 9223 and the http server uses 8080.

After I do a build I do not find the server side code in build/bin.

What do I do next to install everything so that I could try run ws_server.dart and connect from my browser?

My Editor organization:

Server
  packages
  bin
    packages
    fireimager_server.dart (server side websocket handling code)
  build
    bin
    web
  lib
    communication.dart  (common code)
  web
    index.html
    main.css
    main.dart
    WebsocketClient.dart  (client websocket code)
È stato utile?

Soluzione

If you follow the package layout convention, you server.dart should be in $PROJECT/bin and your web stuff in $PROJECT/web.

By running pub build you should get a new directory $PROJECT/build/web. Now you can use the following server.dart code to expose this build directory :

library simple_http_server;

import 'dart:io';
import 'package:http_server/http_server.dart' show VirtualDirectory;

void main() {
  final MY_HTTP_ROOT_PATH = Platform.script.resolve('../build/web').toFilePath();
  final virDir = new VirtualDirectory(MY_HTTP_ROOT_PATH)
    ..allowDirectoryListing = true;

  HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 8080).then((server) {
    server.listen((request) {
      virDir.serveRequest(request);
    });
  });
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top