Created
July 12, 2018 18:14
-
-
Save graphicbeacon/57e478bd917f7a5f723ebb8882378177 to your computer and use it in GitHub Desktop.
Sample code for "Deploying Dart 2 apps to Heroku" on Medium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io' show Platform; | |
import 'dart:async' show runZoned; | |
import 'package:path/path.dart' show join, dirname; | |
import 'package:shelf/shelf_io.dart' as io; | |
import 'package:shelf_static/shelf_static.dart'; | |
void main() { | |
// Assumes the server lives in bin/ and that `webdev build` ran | |
var pathToBuild = join(dirname(Platform.script.toFilePath()), '..', 'build'); | |
var handler = createStaticHandler(pathToBuild, defaultDocument: 'index.html'); | |
var portEnv = Platform.environment['PORT']; | |
var port = portEnv == null ? 9999 : int.parse(portEnv); | |
runZoned(() { | |
io.serve(handler, '0.0.0.0', port); | |
print("Serving $pathToBuild on port $port"); | |
}, onError: (e, stackTrace) => print('Oh noes! $e $stackTrace')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment