Conversation
|
I would really like to see the PR go through. I can't find another elegant solution for a flutter web project to communicate with a cloud run backend. |
|
I'd love to look at this. A bit slammed this week. I'll dig in next week. |
|
I've just been attempting to use this PR (as I really need to find a solution for the CORS issue) but I'm not having any luck -unless I'm misunderstanding I think the implementation could be flawed as it requires editing of the generated file: bin/server.dart// GENERATED CODE - DO NOT MODIFY BY HAND
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import 'dart:io';
import 'package:cloud_functions_core/core.dart';
import 'package:functions_framework/serve.dart';
import 'package:shelf/shelf.dart';
import 'package:update_claims/functions.dart' as function_library;
Future<void> main(List<String> args) async {
await serve(
args,
_nameToFunctionTarget,
customMiddleware: corsHeaders(originChecker: (origin) {
return Cors.domains.contains(origin);
}),
);
}
FunctionTarget? _nameToFunctionTarget(String name) {
switch (name) {
case 'function':
return FunctionTarget.http(
function_library.function,
);
default:
return null;
}
}If my understanding is correct, then I think this solution would need implementing in the builder. The function method is exposed to the server.dart file via the If this PR doesn't go through, @kevmoo do you have any suggestions for resolving the CORS issue in a functions_framework + flutter web combo? |
|
I have taken the idea from this PR, but moved the middleware from server.dart to the functions file, details here: #222 (comment) |
|
I've been super slammed. Thanks for your patience waiting for me here! |
|
Have you seen pkg:gcp? If you just want to use cloud run and get some of those features, you can use pkg:gcp Or are you actually handling "functions"? |
autoCompressviaserveso it can be passed to the created servercustomMiddlewareattribute viaservefor CORS supportfullstack/frontendwhen running on Flutter Web as it was previously failing due to lack of CORS support