<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shtanko Michael on Medium]]></title>
        <description><![CDATA[Stories by Shtanko Michael on Medium]]></description>
        <link>https://medium.com/@shtanko-michael?source=rss-8fed27a85b36------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*b4wsln63uI7GPPTA9eM6cA.jpeg</url>
            <title>Stories by Shtanko Michael on Medium</title>
            <link>https://medium.com/@shtanko-michael?source=rss-8fed27a85b36------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 09:28:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shtanko-michael/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Multiple Layouts in React app with React Router v5]]></title>
            <link>https://shtanko-michael.medium.com/multiple-layouts-in-react-app-with-react-router-v5-2eb6a065e3c5?source=rss-8fed27a85b36------2</link>
            <guid isPermaLink="false">https://medium.com/p/2eb6a065e3c5</guid>
            <category><![CDATA[layout]]></category>
            <category><![CDATA[react-router]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Shtanko Michael]]></dc:creator>
            <pubDate>Wed, 13 May 2020 21:02:09 GMT</pubDate>
            <atom:updated>2020-12-05T16:04:04.311Z</atom:updated>
            <content:encoded><![CDATA[<p>How to use different layouts with React Router v5 to prevent remounting</p><p>Working on large projects we are constantly faced with the need to separate our application into sections, each of which uses its own layout. There are many cases when we need to use several layouts on a site. The simplest example is when we need to separate the administrative part from the client part or, for example, slightly change the page layout for an unauthorized user. In this article I would like to talk about how to use many layouts in React application using React Router v5 without redundant mountings.</p><p>Before I start, I would like to clearly define the goals of this article:</p><ul><li>To prevent remounting layouts on route changes (within the same layout), because this behavior gives an overhead, and can also break transitions, etc.</li><li>To prevent mounting of a layout, which includes the current route, which a user does not have access to (due to permissions or authorization)</li></ul><p>Let’s imagine that there are two layouts in out application: MainLayout and AuthLayout. The first layout is needed for the main part of the site that authorized users can see, and the second one for registration, login, password recovery pages, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fQfYLhMmZ9aJG2oTEW4APw.png" /></figure><p>In this example, MainLayout contains the sidebar, header, footer and page content, and AuthLayout contains only the right panel with the form inside.</p><p>You can see sample code for the layouts below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d830fb659c3a9e7546069420f62043eb/href">https://medium.com/media/d830fb659c3a9e7546069420f62043eb/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be814bccf62dd606578340b62e4993e3/href">https://medium.com/media/be814bccf62dd606578340b62e4993e3/href</a></iframe><p>So, now we need to tell React that we want to use different layouts for different routes. By using React Router v5, route declarations are performed using Route component. This component <a href="https://github.com/ReactTraining/react-router/pull/5889/commits/4b79b968389a5bda6141ac83c7118fba9c25ff05">is able to take an array of paths</a>, which greatly facilitates the use of different layouts. We can create Route component thus which will fire when the current URL matches one of the specified paths and mount the layout first, and only then the target page itself.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/902557323b87bea00db2c160c7318baa/href">https://medium.com/media/902557323b87bea00db2c160c7318baa/href</a></iframe><p>So we have already achieved one of our goals, namely, when switching between /login and /register routes, AuthLayout will not mount again, but will only change its children.</p><p>But what to do when we need to deny access to certain pages? Here we can use the classic React approach and create a simple PrivateRoute component. But we will not use it for each individual route, but for the whole layout, because otherwise React <strong>will first mount the layout</strong> and only then get to PrivateRoute with the target page and check access to it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/90ccbae46e2295f9fa83ad18af07b9a5/href">https://medium.com/media/90ccbae46e2295f9fa83ad18af07b9a5/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7cfe652724d232f8c6eedf13f667ece/href">https://medium.com/media/c7cfe652724d232f8c6eedf13f667ece/href</a></iframe><p>We have achieved all our goals, now React will not even mount the layout if a user does not have access to its pages. But there is a problem. As you can see, we are forced to duplicate each route, first for the layout, and then for the page itself. With the increase in the number of routes, their support will become a large problem. I suggest using static routes to configure application’s routing.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/92b1e1d62f81ed70edf4b44ac51932b6/href">https://medium.com/media/92b1e1d62f81ed70edf4b44ac51932b6/href</a></iframe><p>In this case, the routes will be configured approximately as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/76dba1c32acd3d8ab4e84fd36267e970/href">https://medium.com/media/76dba1c32acd3d8ab4e84fd36267e970/href</a></iframe><p>This approach allows you to use an unlimited number of templates without any overhead.</p><p>That’s it! I hope this article was helpful for you. For more information you can use <a href="https://github.com/shtanko-michael/react-multiple-layouts-example">this repository</a>.<br>If you have any questions or suggestions, let me know in the comments. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2eb6a065e3c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mocking AWS with LocalStack in .NET Core 3]]></title>
            <link>https://shtanko-michael.medium.com/mocking-aws-with-localstack-in-net-core-3-ef32ae888706?source=rss-8fed27a85b36------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef32ae888706</guid>
            <category><![CDATA[mocking]]></category>
            <category><![CDATA[localstack]]></category>
            <category><![CDATA[aspnetcore]]></category>
            <category><![CDATA[amazon]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Shtanko Michael]]></dc:creator>
            <pubDate>Tue, 04 Feb 2020 18:17:15 GMT</pubDate>
            <atom:updated>2020-02-04T18:17:15.265Z</atom:updated>
            <content:encoded><![CDATA[<h3>Mocking AWS with LocalStack in .NET Core 3</h3><h4><strong>Configuring an ASP.NET Core application to interact with AWS mocks</strong></h4><p><strong>Amazon Web Services</strong> offers a lot of products and cloud services. It is almost impossible to find an enterprise application developed without any AWS service. It can be virtual servers, scalable data storages, relational or NoSQL databases or a bunch of other services.</p><p>Any of the Amazon’s services requires configuration before use, at least for development and production stages. And if the number of services you use exceeds two, then it may take a long time. And you also have to pay for using Amazon’s services even during development and testing.</p><p>So what are we supposed to do about it? Right, let’s set up a free local environment that mocks all Amazon’s services!</p><h3>What is LocalStack?</h3><p>LocalStack is a framework by Atlassian needed to mock and test all Amazon’s services right on your local machine. It provides the same APIs and opportunities as the real AWS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DLU43UKMhbCbLXNV4oXX4A.png" /><figcaption>LocalStack infrastructure (source <a href="https://localstack.cloud/">https://localstack.cloud</a>)</figcaption></figure><h4>Benefits of using LocalStack:</h4><ul><li>You can save money during development and testing</li><li>You can work offline!</li><li>More straightforward and convenient debugging. No one else can use your own services.</li><li>Very fast introduction of new Amazon services in the application</li><li>You still can use <strong>aws cli</strong> to easily control each of your services.<br>All you need to do is add <em>endpoint </em>argument to any request.<br>For example, to create an Amazon SQS queue:</li></ul><pre>aws sqs create-queue --queue-name MyQueue --endpoint http://localhost:4576</pre><h3>Installing LocalStack on your local machine</h3><ul><li>Install <a href="https://www.python.org/downloads/release/python-376/">Python</a> (&lt;=3.7.x) including <strong>pip</strong> (python package manager)</li></ul><blockquote>I couldn’t install LocalStack via pip with the latest Python version 3.8.1 installed</blockquote><ul><li>Install <a href="https://docs.docker.com/install/"><strong>Docker</strong></a></li><li>Install <strong>LocalStack </strong>via <strong>pip</strong></li></ul><pre>pip install localstack</pre><ul><li>Run to launch LocalStack’s servises using Docker by default</li></ul><pre>localstack start</pre><blockquote>You can also use custom docker-compose.yml <em>file, </em><a href="https://github.com/localstack/localstack#using-docker-compose"><em>more info here</em></a></blockquote><p>Moreover you can avoid of using Docker and launch LocalStack in <a href="https://github.com/localstack/localstack#starting-locally-non-docker-mode">non-Docker mode</a> using <em>host </em>argument<em>, </em>but it will require <a href="https://github.com/localstack/localstack#Developing">addition dependencies</a> and may cause bugs :)</p><pre>localstack start --host</pre><h3>Using LocalStack services within .NET Core 3 application</h3><p>Let’s say, we need to build a simple file manager application using Amazon S3 as a file storage, Amazon CloudFront for caching and Amazon CloudWatch for logging.</p><p>First of all we need to configure our mock environment. We can do it using <strong>aws cli</strong> or any GUI client (for example, <a href="https://getcommandeer.com/">Commandeer</a>). Personally I prefer console way.</p><ul><li>Install <a href="https://aws.amazon.com/cli/"><strong>aws cli</strong></a> tool</li><li>Configure local profile using your personal access and secret tokens. It can be fake tokens, you can easily use tokens like <strong>«ACCESS TOKEN» </strong>as an access token and <strong>«SECRET TOKEN» </strong>as a secret, respectively.<br>Use <strong>us-east-1</strong> as a default region and <strong>json </strong>as an output format</li></ul><pre>aws configure</pre><ul><li>Create S3 bucket <em>dev-files </em>and make it public by default</li></ul><pre>aws s3 mb s3://dev-files --endpoint <a href="http://localhost:4572/">http://localhost:4572</a></pre><pre>aws s3api put-bucket-acl --bucket dev-files --acl public-read-write --endpoint <a href="http://localhost:4572/">http://localhost:4572</a></pre><blockquote>Because CloudFront is available only in pro version of LocalStack we just use S3 instead to emulate similar behaviour.</blockquote><p>That’s it. We have configured our local AWS environment. Let’s use it in code!</p><p>Let’s configure our project to use mock services instead of real ones in <em>Development</em> stage. In my case it’s Amazon S3 client and Amazon CloudWatch client.</p><ul><li>Install several nuget packages</li></ul><pre>dotnet add package AWSSDK.S3 --version 3.3.110.1<br>dotnet add package AWSSDK.CloudWatchLogs --version 3.3.101.78<br>dotnet add package AWSSDK.Extensions.NETCore.Setup --version 3.3.100.1</pre><pre>dotnet add package Serilog.AspNetCore --version 3.2.0<br>dotnet add package Serilog.Sinks.AwsCloudWatch --version 4.0.155</pre><blockquote>The last two packages are used because I prefer <a href="https://serilog.net/">Serilog</a> as the default library for logging</blockquote><ul><li>Now we can replace real Amazon services with LocalStack services in <em>ConfigureServices </em>method of <em>Startup.cs</em></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/067daeb660daa0ee948eeea605065b8c/href">https://medium.com/media/067daeb660daa0ee948eeea605065b8c/href</a></iframe><blockquote>AppSettings here is a custom class describing <strong>appsettings.{ENV}.json. </strong>It is used to strongly typify project settings.</blockquote><p>All we have left to do is configure Serilog in <strong><em>Configure </em></strong>method of <strong><em>Startup.cs</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc990fdd1c6f0c3e76a7285154d5da4f/href">https://medium.com/media/bc990fdd1c6f0c3e76a7285154d5da4f/href</a></iframe><p>And don’t forget to call <strong><em>UseSerilog </em></strong>method in <strong><em>Program.cs</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d09272f8e656066b4703d2e48403484c/href">https://medium.com/media/d09272f8e656066b4703d2e48403484c/href</a></iframe><p>This is how <strong><em>appsettings.Development.json</em></strong> file looks like just in case</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59b7308fe6e350e49168f9875e80dbf8/href">https://medium.com/media/59b7308fe6e350e49168f9875e80dbf8/href</a></iframe><p>It’s time to check out our services! Just inject them into the constructor of any controller or somewhere else where you need it and use it.</p><p>This is the simplest example of using these services.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a86aae315a4d1206a69e32e6d7e30586/href">https://medium.com/media/a86aae315a4d1206a69e32e6d7e30586/href</a></iframe><p>Let’s upload some file to our local S3 storage usign <a href="https://curl.haxx.se/"><strong>cURL</strong></a></p><pre>curl -F `file=<a href="http://twitter.com/file_to_upload">@file</a>.jpg&#39; <a href="https://localhost:44312/file/upload">https://localhost:44312/file/upload</a></pre><p>Now our GET-request should return something like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd5b31d0294387ee36f33240b7c036ea/href">https://medium.com/media/dd5b31d0294387ee36f33240b7c036ea/href</a></iframe><p>If we call a download request using id of any of the previously uploaded files, we should get a presigned link that expires in one day from this moment</p><pre>curl <a href="https://localhost:44312/file/download/%7Bkey%7D">https://localhost:44312/file/download/{key}</a></pre><p>After you copy the link and paste it into your browser, the file should be downloaded without browser’s preview.</p><p>And one more thing! To make sure our logger is working properly just use this command:</p><pre>aws logs get-log-events --log-group-name dev-logs --log-stream-name YYYY-MM-DD --endpoint http://localhost:4586</pre><blockquote>where <strong>YYYY-MM-DD</strong> is today’s date according to our <strong>LogStreamNameProvider</strong></blockquote><p>You should see something like this. If so, then all of our services work perfectly!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*QvLPZEQUUnf__zkFFRxBMA.png" /></figure><p>That’s it! I hope this article was helpful for you. If you have any questions or suggestions, let me know in the comments. Thank you for reading!</p><p>PS: You can find my simple file manager implementation in GitHub by <a href="https://github.com/shtanko-michael/localstack-file-manager">this link</a>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*8qMBWW8amxVjcUCrqaewIA.png" /><figcaption>A simple file manager preview</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef32ae888706" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>