diff --git a/samples/wine_cellar_sample/winecellarserver/MainWebModuleUnit.pas b/samples/wine_cellar_sample/winecellarserver/MainWebModuleUnit.pas index bd9e0f8c..20400568 100644 --- a/samples/wine_cellar_sample/winecellarserver/MainWebModuleUnit.pas +++ b/samples/wine_cellar_sample/winecellarserver/MainWebModuleUnit.pas @@ -28,6 +28,7 @@ implementation uses WineCellarAppControllerU, MVCFramework.Middleware.StaticFiles, + MVCFramework.Middleware.CORS, System.IOUtils; {$R *.dfm} @@ -40,6 +41,7 @@ begin // Conf.Value[tmvcconfigkey.PathPrefix] := '/dmvc'; end); MVCEngine.AddController(TWineCellarApp); + MVCEngine.AddMiddleware(TMVCCORSMiddleware.Create); if not IsLibrary then begin MVCEngine.AddMiddleware(TMVCStaticFilesMiddleware.Create('/app', { StaticFilesPath } diff --git a/sources/MVCFramework.Commons.pas b/sources/MVCFramework.Commons.pas index 3cf149d6..c62b956f 100644 --- a/sources/MVCFramework.Commons.pas +++ b/sources/MVCFramework.Commons.pas @@ -673,6 +673,7 @@ function BuildContentType(const aContentMediaType: string; const aContentCharSet function StrToJSONObject(const aString: String; ARaiseExceptionOnError: Boolean = False): TJsonObject; function StrToJSONArray(const aString: String; ARaiseExceptionOnError: Boolean = False): TJsonArray; function ObjectToJSONObject(const aObject: TObject): TJSONObject; +function ObjectToJSONObjectStr(const aObject: TObject): String; function WrapAsList(const AObject: TObject; AOwnsObject: Boolean = False): IMVCList; @@ -1788,6 +1789,18 @@ begin end; end; +function ObjectToJSONObjectStr(const aObject: TObject): String; +var + lJSON: TJsonObject; +begin + lJSON := ObjectToJSONObject(aObject);; + try + Result := lJSON.ToJSON(True); + finally + lJSON.Free; + end; +end; + function StrToJSONObject(const aString: String; ARaiseExceptionOnError: Boolean = False): TJsonObject; begin Result := MVCFramework.Utils.StrToJSONObject(aString, ARaiseExceptionOnError);