dart-shelf

incompatibility when running dart rpc and shelf (with shelf_rpc) related to headers which are lists (and not Strings)

99封情书 提交于 2019-12-24 17:53:19
问题 incompatibility when running dart rpc and shelf (with shelf_rpc) related to headers which are lists (and not Strings). It seems that there is an incompatibility when running dart rpc and shelf (with shelf_rpc) related to headers which are lists (and not Strings). Error thrown is ( for shelf[0.5.7], shelf_rpc[0.0.3], rpc[0.4.2]: ): Error thrown by handler. type 'List' is not a subtype of type 'String' of 'value'. package:collection/src/canonicalized_map.dart 66:30 CanonicalizedMap.[]= package

How to create/add middleware that adds default headers to each request

笑着哭i 提交于 2019-12-19 09:04:53
问题 How can I add middleware to the shelf pipeline that adds default HTTP headers to each request? 回答1: Update There is now a pub package to simplify adding CORS headers see https://pub.dartlang.org/packages/shelf_cors Original See also https://groups.google.com/a/dartlang.org/forum/#!topic/cloud/2Vn_IqzGtTc final Map<String, String> _headers = {'Access-Control-Allow-Origin': '*', 'Content-Type': 'text/html'}; // for OPTIONS (preflight) requests just add headers and an empty response shelf

Server response with output from Future Object

我是研究僧i 提交于 2019-12-11 16:28:11
问题 i created a async/await function in another file thus its handler is returning a Future Object. Now i can't understand how to give response to client with content of that Future Object in Dart. I am using basic dart server with shelf package.Below is code where ht.handler('list') returns a Future Object and i want to send that string to client as response. But i am getting internal server error. import 'dart:io'; import 'package:args/args.dart'; import 'package:shelf/shelf.dart' as shelf;

How do I validate an established session using the shelf_auth library?

て烟熏妆下的殇ゞ 提交于 2019-12-11 09:55:43
问题 I've been trying to write a simple server that accepts username/password credentials, validates them, then creates a JWT token for the client that they then use to gain access to certain routes. I am able to do everything up to the point of receiving and validating the client's JWT on the server side. void main() { //use Jwt based sessions and create the secret using a UUID JwtSessionHandler sessionHandler = new JwtSessionHandler('ffl_sales_server', new Uuid().v4(), auth.lookupByUsername); /

Authenticate websocket connection in Dart using shelf_auth and shelf_web_socket

不问归期 提交于 2019-12-11 08:27:19
问题 Using shelf_auth I can extract current user information from request this way: getAuthenticatedContext(request) .map((ac) => ac.principal.name) .getOrElse(() => 'guest') but, obviously, I need a request for that to work :) On the other hand, using shelf_web_socket, establishing of websocket connection executes handler like that: handleWS(CompatibleWebSocket ws){ // Here I should get user from getAuthenticatedContext() // but I cannot due to absence of Request here. ws.messages.listen(...); };

How to serve both dynamic and static pages with Dart and shelf?

半世苍凉 提交于 2019-12-09 05:44:58
问题 Using shelf_static to serve static web pages through Dart is no problem: var staticHandler = createStaticHandler(staticPath, defaultDocument:'home.html'); io.serve(staticHandler, 'localhost', port).then((server) { print('Serving at http://${server.address.host}:${server.port}'); }); and I can use shelf_route fine for dynamic web pages: Router routes = new Router() ..get('/item/{itemid}', handler.doItem); var handler = const shelf.Pipeline() .addHandler(routes.handler); io.serve(handler,

How to serve both dynamic and static pages with Dart and shelf?

只谈情不闲聊 提交于 2019-12-03 06:53:05
Using shelf_static to serve static web pages through Dart is no problem: var staticHandler = createStaticHandler(staticPath, defaultDocument:'home.html'); io.serve(staticHandler, 'localhost', port).then((server) { print('Serving at http://${server.address.host}:${server.port}'); }); and I can use shelf_route fine for dynamic web pages: Router routes = new Router() ..get('/item/{itemid}', handler.doItem); var handler = const shelf.Pipeline() .addHandler(routes.handler); io.serve(handler, 'localhost', port).then((server) { print('Serving at http://${server.address.host}:${server.port}'); }); But