Skip to content

Commit

Permalink
server fix, readme
Browse files Browse the repository at this point in the history
  • Loading branch information
johnpryan committed Jan 10, 2018
1 parent 0c4ae6f commit 85bba15
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 14 deletions.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,39 @@
# letsvote

LetsVote demonstrates how code can be shared across web, mobile, and the server.

It uses Flutter for iOS / Android, Polymer for the web, and
[shelf](https://pub.dartlang.org/packages/shelf) on the server

# How to run

Use pub to run the web app:

```
cd letsvote_web
pub get
pub serve
```

Use flutter to run the mobile app:

```
cd letsvote_mobile
flutter packages get
flutter run
```

Use dart to run the web server:

```
cd letsvote_web
pub get
pub run bin/server.dart
```

# Configuration

Use `letsvote_web/web/config.yaml` to configure what server the web connects to.



21 changes: 16 additions & 5 deletions letsvote_web/bin/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:io';
import 'package:args/args.dart';
import 'package:path/path.dart' as path;
import 'package:shelf/shelf.dart' as shelf;
import 'package:shelf/shelf.dart';
import 'package:shelf_static/shelf_static.dart' as shelf_static;
import 'package:shelf_route/shelf_route.dart' as shelf_route;
import 'package:shelf/shelf_io.dart' as io;
Expand All @@ -14,8 +15,14 @@ void main(List<String> args) {
// the server lives in bin/ and that `pub build` ran
var pathToBuild =
path.join(path.dirname(Platform.script.toFilePath()), '..', 'build/web');
var staticHandler = shelf_static.createStaticHandler(pathToBuild,
defaultDocument: 'index.html');

Handler staticHandler;
try {
staticHandler = shelf_static.createStaticHandler(pathToBuild,
defaultDocument: 'index.html');
} catch(e) {
// support running without a build/ directory
}

var portEnv = Platform.environment['PORT'];
var port = portEnv == null ? 9999 : int.parse(portEnv);
Expand All @@ -38,8 +45,12 @@ void main(List<String> args) {
server.configureRoutes(appRouter);

var pipeline = new shelf.Pipeline();
var cascade =
new shelf.Cascade().add(staticHandler).add(appRouter.handler).handler;
var cascade = new shelf.Cascade();
if (staticHandler != null) {
cascade = cascade.add(staticHandler);
}
cascade = cascade.add(appRouter.handler);

var corsHeaders = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Content-Type',
Expand All @@ -48,7 +59,7 @@ void main(List<String> args) {
var corsMiddleware =
shelf_cors.createCorsHeadersMiddleware(corsHeaders: corsHeaders);
pipeline = pipeline.addMiddleware(corsMiddleware);
var handler = pipeline.addHandler(cascade);
var handler = pipeline.addHandler(cascade.handler);

io.serve(handler, '0.0.0.0', port).then((server) {
print('Serving at http://${server.address.host}:${server.port}');
Expand Down
17 changes: 8 additions & 9 deletions letsvote_web/web/components/lv_app.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
@apply(--layout-flex);
@apply(--layout-vertical);
}

paper-card {
@apply(--layout-flex);
margin: 8px;
}
</style>
<template>
<template is="dom-if" if="[[isLoading]]">
Expand Down Expand Up @@ -43,7 +38,8 @@ <h1>Let's Vote!</h1>
<!-- Page.joining -->
<p>Enter the code for your vote:</p>
<paper-input placeholder="4-letter code"
value="{{enteredCode}}"></paper-input>
value="{{enteredCode}}"
maxlength="4"></paper-input>
<paper-button on-tap="handleJoin">Submit
</paper-button>
</neon-animatable>
Expand Down Expand Up @@ -71,8 +67,10 @@ <h1>Let's Vote!</h1>
<p>code: [[code]]</p>
<p>Topic: [[topic]]</p>
<paper-radio-group selected="{{selectedVoteIdea}}">
<template is="dom-repeat" items="[[voteIdeas]]" as="idea">
<paper-radio-button name="[[idea]]">[[idea]]</paper-radio-button>
<template is="dom-repeat" items="[[voteIdeas]]"
as="idea">
<paper-radio-button name="[[idea]]">[[idea]]
</paper-radio-button>
</template>
</paper-radio-group>
<paper-button on-tap="handleVoteEntered">Vote</paper-button>
Expand All @@ -82,7 +80,8 @@ <h1>Let's Vote!</h1>
<p>code: [[code]]</p>
<p>Topic: [[topic]]</p>
<template is="dom-if" if="[[isCreator]]">
<paper-button on-tap="closePolls">Close Polls</paper-button>
<paper-button on-tap="closePolls">Close Polls
</paper-button>
</template>
<p>waiting for the polls to close...</p>
</neon-animatable>
Expand Down

0 comments on commit 85bba15

Please sign in to comment.