Commit bb2f54bb authored by Adam Barth's avatar Adam Barth

Use shelf instead of http_server

This patch switches sky_server.dart to use shelf rather than http_server.
parent 6d8255ff
...@@ -2,10 +2,11 @@ ...@@ -2,10 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:async';
import 'dart:io'; import 'dart:io';
import 'package:http_server/http_server.dart'; import 'package:shelf_static/shelf_static.dart';
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf/shelf.dart';
const String usage = 'Usage: sky_server PORT'; const String usage = 'Usage: sky_server PORT';
...@@ -23,26 +24,21 @@ main(List<String> argv) async { ...@@ -23,26 +24,21 @@ main(List<String> argv) async {
return; return;
} }
VirtualDirectory currentDirectory = new VirtualDirectory('.') Handler handler = createStaticHandler(Directory.current.path,
..followLinks = true serveFilesOutsidePath: true);
..jailRoot = false
..allowDirectoryListing = true;
HttpServer server; HttpServer server;
try { try {
server = await HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, port); server = await io.serve(handler, InternetAddress.LOOPBACK_IP_V4, port);
} catch(e) { } catch(e) {
print(e); print(e);
return; return;
} }
server.autoCompress = true;
server.defaultResponseHeaders server.defaultResponseHeaders
..removeAll('x-content-type-options') ..removeAll('x-content-type-options')
..removeAll('x-frame-options') ..removeAll('x-frame-options')
..removeAll('x-xss-protection') ..removeAll('x-xss-protection')
..add('cache-control', 'no-cache'); ..add('cache-control', 'no-cache');
server
..autoCompress = true
..listen(currentDirectory.serveRequest);
} }
author: Chromium Authors <sky-dev@googlegroups.com> author: Chromium Authors <sky-dev@googlegroups.com>
dependencies: dependencies:
args: ^0.13.0 args: ^0.13.0
http_server: ^0.9.5 shelf: ^0.6.2
shelf_static: ^0.2.2
description: Tools for building Sky applications description: Tools for building Sky applications
environment: environment:
sdk: ">=1.8.0 <2.0.0" sdk: ">=1.8.0 <2.0.0"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment