Add a basic HTTP server for Sky

This commit is contained in:
Adam Barth
2015-07-22 23:42:22 -07:00
parent 646ff43f9b
commit 041275e80c
2 changed files with 50 additions and 1 deletions

View File

@@ -0,0 +1,48 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'package:http_server/http_server.dart';
const String usage = 'Usage: sky_server PORT';
main(List<String> argv) async {
if (argv.length != 1) {
print(usage);
return;
}
int port;
try {
port = int.parse(argv[0]);
} catch(e) {
print(usage);
return;
}
VirtualDirectory currentDirectory = new VirtualDirectory('.')
..allowDirectoryListing = true;
HttpServer server;
try {
server = await HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, port);
} catch(e) {
print(e);
return;
}
server.defaultResponseHeaders
..removeAll('x-content-type-options')
..removeAll('x-frame-options')
..removeAll('x-xss-protection')
..add('cache-control', 'no-cache');
server
..autoCompress = true
..listen(currentDirectory.serveRequest);
print('Sky server running on port $port');
}

View File

@@ -1,6 +1,7 @@
author: Chromium Authors <sky-dev@googlegroups.com>
dependencies:
args: '>=0.13.0 <1.0.0'
args: ^0.13.0
http_server: ^0.9.5
description: Tools for building Sky applications
homepage: https://github.com/domokit/sky_tools
name: sky_tools