Created
April 29, 2015 08:16
-
-
Save ThomasLocke/1e6b6e6ae344c099cef3 to your computer and use it in GitHub Desktop.
shelf_path woes
This file contains hidden or 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
library shelfmiddleware.checktoken; | |
import 'headers.dart'; | |
import 'token.dart'; | |
import 'package:shelf/shelf.dart' as shelf; | |
import 'package:shelf_path/shelf_path.dart'; | |
final shelf.Middleware checkToken = shelf.createMiddleware(requestHandler: _passOrForbid); | |
shelf.Response _passOrForbid(shelf.Request request) { | |
final String token = Uri.splitQueryString(request.url.query)['token']; | |
print('BEGIN'); | |
print(getPathParameter(request, 'token')); // This is null.. | |
print('END'); | |
if(isValid(token)) { | |
return null; | |
} | |
final String newToken = getToken(); | |
final String html = ''' | |
<h1>Grab a Token!</h1> | |
<p>Click <a href="/app?token=${newToken}">here</a> to venture forth to app/</p> | |
<p>Token: ${newToken} | |
'''; | |
return new shelf.Response.forbidden(html, headers: textHtmlHeader); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment