Skip to content

React.Owin #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 18, 2015
Merged

React.Owin #69

merged 10 commits into from
Jan 18, 2015

Conversation

mandrek44
Copy link
Contributor

React.Owin

I've created Owin middleware for serving transformed JSX files. It's built on top core React library and Owin / Katana StaticFileMiddleware.

I know it's a big pull request, but since I already written it to use in my project, I thought I could share the code.

Why Owin?

Owin compatible code begins to take lot of attention in .NET. WebAPI 2 can be treated just as Owin middleware, and MVC 6 will be completely based on Owin.

I'm developing a web app in react.js, hosted on Owin-based service. To take advantage of server-side JSX transformation, I created middleware that uses React.Net to serve JSX files compiled to JavaScript.

Structure

I tried to retain the structure and standards of existing React.NET code: every file has a Facebook boilerplate, project libraries have links to shared assembly info files and there's included sample project that uses Microsoft.Owin.SelfHost.

The most important classes are:

  • JsxFileMiddleware which is wrapper around Owin StaticFileMiddleware, but uses it's own FileSystem.
  • JsxFileSystem - a decorator class around IFileSystem - that transforms the JSX file when requested.

Tests

I didn't include any tests for the code - it's hard for me to come up with something. Cache implementation is rather straightforward usage of System.Runtime.Caching, middleware itself configures built-in StaticFileMiddleware, and JsxFileSystem (which handles the transformation) is almost entirely based on IJsxTransformer.

public override string MapPath(string relativePath)
{
if (relativePath.StartsWith("~"))
return Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), relativePath.Replace("~", string.Empty));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be unit tested?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assembly.GetEntryAssembly() will be null under nunit runner. I can change design to get around this somehow, however I'm not sure if this is good idea for something that simple

<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused references

@Daniel15
Copy link
Member

Thanks for this! I just wrote a bunch of comments.

Please ensure you're using the same assembly settings as the rest of ReactJS.NET. Notably, "warnings as errors" should be enabled for release builds. Use tabs for indentation in C# files.

Also please don't add jQuery to any examples. Ideally I'd like if you reused the same sample code from React.Sample.Mvc4 for consistency.

Please run the release-build.bat script and ensure that build succeeds.

@mandrek44
Copy link
Contributor Author

Thanks for all your effort to do this review! I hope I covered all your comments.

I used the sample code from React.Sample.Mvc, however I had to change it bit to adjust to Owin environment - it loads initial comments asynchronously.

/// <param name="container">Container to register components in</param>
public void Register(TinyIoCContainer container)
{
container.Register<IFileSystem, EntryAssemblyFileSystem>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the indentation to use tabs everywhere - This file is a mix of spaces and tabs.

@Daniel15
Copy link
Member

Thanks for working on this! I really appreciate it :)

Daniel15 added a commit that referenced this pull request Jan 18, 2015
@Daniel15 Daniel15 merged commit 5b4b52a into reactjs:master Jan 18, 2015
@Daniel15
Copy link
Member

I've merged your changes! It would be awesome to get some documentation on this feature (just a Markdown file in site/jekyll/guides) but that's totally optional and I can write something if you don't get around to it. Just a basic explanation of what's supported and how to use it :)

Again, thanks! :D

@Daniel15 Daniel15 added this to the 1.4 milestone Mar 1, 2015
@ilyapalkin
Copy link

Is there a nuget package with React.Owin?

Daniel15 added a commit that referenced this pull request Apr 13, 2015
@Daniel15
Copy link
Member

@ilyapalkin Good point! I just noticed there's no NuGet package for React.Owin. Hahaha. Just created a config for it, it will be available with the next ReactJS.NET release (which should be soon), or you could use the version off the build server once it picks up the change.

@Daniel15
Copy link
Member

NuGet package is up now: https://www.nuget.org/packages/React.Owin/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants