<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hozefa Mangalorewala</title>
    <description>The latest articles on DEV Community by Hozefa Mangalorewala (@hozefam).</description>
    <link>https://dev.to/hozefam</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F53585%2Fb63fa962-bf00-4558-972d-9b459f253183.png</url>
      <title>DEV Community: Hozefa Mangalorewala</title>
      <link>https://dev.to/hozefam</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hozefam"/>
    <language>en</language>
    <item>
      <title>CORS how to enable them in .NET?</title>
      <dc:creator>Hozefa Mangalorewala</dc:creator>
      <pubDate>Sun, 18 Dec 2022 10:57:24 +0000</pubDate>
      <link>https://dev.to/hozefam/cqrs-how-to-enable-them-in-net-511k</link>
      <guid>https://dev.to/hozefam/cqrs-how-to-enable-them-in-net-511k</guid>
      <description>&lt;p&gt;These two URLs have the same origin:&lt;br&gt;
𝗁𝗍𝗍𝗉𝗌://𝗆𝗒-𝗌𝗂𝗍𝖾-𝗇𝗈-𝟣.𝖼𝗈𝗆/𝖦𝖾𝗍/𝖧𝖺𝗄𝗎𝗇𝖺𝖬𝖺𝗍𝖺𝗍𝖺&lt;br&gt;
𝗁𝗍𝗍𝗉𝗌://𝗆𝗒-𝗌𝗂𝗍𝖾-𝗇𝗈-𝟣.𝖼𝗈𝗆/𝖦𝖾𝗍/𝖠𝗅𝗅𝖨𝗌𝖶𝖾𝗅𝗅&lt;/p&gt;

&lt;p&gt;These URLs have different origins&lt;br&gt;
𝗁𝗍𝗍𝗉𝗌://𝗆𝗒-𝗌𝗂𝗍𝖾-𝗇𝗈-𝟣.𝖼𝗈𝗆/𝖦𝖾𝗍/𝖧𝖺𝗄𝗎𝗇𝖺𝖬𝖺𝗍𝖺𝗍𝖺&lt;br&gt;
𝗁𝗍𝗍𝗉://𝗆𝗒-𝗌𝗂𝗍𝖾-𝗇𝗈-𝟣.𝗇𝖾𝗍/𝖦𝖾𝗍/𝖠𝗅𝗅𝖨𝗌𝖶𝖾𝗅𝗅&lt;/p&gt;

&lt;p&gt;To facilitate requests from different origins you need to enable CORS in .NET.&lt;/p&gt;

&lt;p&gt;In .NET 6 by using the combination of these methods you can enable CORS as per your requirement.&lt;/p&gt;

&lt;p&gt;𝐀𝐥𝐥𝐨𝐰𝐀𝐧𝐲𝐎𝐫𝐢𝐠𝐢𝐧: This policy allows requests from any origin.&lt;/p&gt;

&lt;p&gt;𝐖𝐢𝐭𝐡𝐎𝐫𝐢𝐠𝐢𝐧𝐬: This policy allows requests from specific origins. You can specify one or more origins as arguments to this method.&lt;/p&gt;

&lt;p&gt;𝐀𝐥𝐥𝐨𝐰𝐀𝐧𝐲𝐇𝐞𝐚𝐝𝐞𝐫: This policy allows requests with any header.&lt;/p&gt;

&lt;p&gt;𝐖𝐢𝐭𝐡𝐇𝐞𝐚𝐝𝐞𝐫𝐬: This policy allows requests with specific headers. You can specify one or more headers as arguments to this method.&lt;/p&gt;

&lt;p&gt;𝐀𝐥𝐥𝐨𝐰𝐀𝐧𝐲𝐌𝐞𝐭𝐡𝐨𝐝: This policy allows requests with any HTTP method (e.g., GET, POST, PUT, DELETE).&lt;/p&gt;

&lt;p&gt;𝐖𝐢𝐭𝐡𝐌𝐞𝐭𝐡𝐨𝐝𝐬: This policy allows requests with specific HTTP methods. You can specify one or more methods as arguments to this method.&lt;/p&gt;

&lt;p&gt;Few Things to Keep in mind&lt;/p&gt;

&lt;p&gt;✔️CORS is not a security feature. CORS is a W3C standard that allows a server to relax the same-origin policy.&lt;/p&gt;

&lt;p&gt;✔️An API isn't safer by allowing CORS.&lt;/p&gt;

&lt;p&gt;✔️It's a way for a server to allow browsers to execute a cross-origin request that otherwise would be forbidden.&lt;/p&gt;

&lt;p&gt;✔️Browsers without CORS can't do cross-origin requests.&lt;/p&gt;

</description>
      <category>cqrs</category>
      <category>dependency</category>
      <category>dotnetcore</category>
      <category>csharp</category>
    </item>
    <item>
      <title>Create a production grade workflow for your React app</title>
      <dc:creator>Hozefa Mangalorewala</dc:creator>
      <pubDate>Sun, 28 Jun 2020 03:45:29 +0000</pubDate>
      <link>https://dev.to/hozefam/create-a-production-grade-workflow-for-react-app-42ec</link>
      <guid>https://dev.to/hozefam/create-a-production-grade-workflow-for-react-app-42ec</guid>
      <description>&lt;h6&gt;
  
  
  PS: This is my first ever post on Dev, I appreciate your feedback and comments. Follow me on twitter &lt;a href="https://twitter.com/hozefam"&gt;@hozefam&lt;/a&gt;
&lt;/h6&gt;

&lt;h2&gt;
  
  
  Requirments
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/"&gt;Github&lt;/a&gt; account (Free)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://travis-ci.org/"&gt;Travis&lt;/a&gt; account (Free)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://aws.amazon.com/free/"&gt;AWS&lt;/a&gt; account (Free but credit card required)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://nodejs.org/en/"&gt;Node&lt;/a&gt; is installed on your local computer&lt;/li&gt;
&lt;li&gt;Basic knowledge of &lt;strong&gt;React&lt;/strong&gt; and &lt;strong&gt;Docker&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is Continous Integration (CI)? Why Travis CI?
&lt;/h2&gt;

&lt;p&gt;Continuous Integration is the practice of merging in small code changes frequently - rather than merging in a large change at the end of a development cycle. The goal is to build healthier software by developing and testing in smaller increments. This is where Travis CI comes in.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;As a continuous integration platform, &lt;strong&gt;Travis CI&lt;/strong&gt; supports your development process by automatically building and testing code changes, providing immediate feedback on the success of the change.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Travis CI can also automate other parts of your development process by managing deployments and notifications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create React App
&lt;/h2&gt;

&lt;p&gt;Create a simple React app using the npm package - &lt;a href="https://www.npmjs.com/package/create-react-app"&gt;Create-react-app&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app docker-react-app
cd docker-react-app
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Once this is done, you can open the folder docker-react-app in any code editor (like &lt;a href="https://code.visualstudio.com/"&gt;VSCode&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;The following folder structure will be created&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uy_ZTE4p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/ak3RhE5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uy_ZTE4p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/ak3RhE5.png" alt="CRA_Source"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Dockerize It
&lt;/h2&gt;

&lt;p&gt;We will create a Docker image of the App and will create 2 files:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Dockerfile.dev&lt;/strong&gt; will contain instructions to build the image and will be used to run tests. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dockerfile&lt;/strong&gt; will contain instructions to build the image and run the optimized version of the application.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What is a Dockerfile?
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;A &lt;strong&gt;Dockerfile&lt;/strong&gt; is a text document that contains all the commands a user could call on the command line to assemble an image.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Dockerfile.dev&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM node:alpine
WORKDIR /app
COPY package.json .
RUN npm install
COPY . . 
CMD ["npm", "start"]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Dockerfile&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM node:alpine
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
RUN ["npm","run", "build"]

FROM nginx
EXPOSE 80
COPY --from=0 /app/build /usr/share/nginx/html
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Checkin all changes to Github Repo
&lt;/h3&gt;

&lt;p&gt;At this stage checkin all the files to github. Here is my &lt;a href="https://github.com/hozefam/docker-react-app"&gt;&lt;strong&gt;link&lt;/strong&gt;&lt;/a&gt; to github repo for the "docker-react-app"&lt;/p&gt;

&lt;p&gt;The repo should look something like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2GGjw1wz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/zVp90ok.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2GGjw1wz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/zVp90ok.png" alt="Github_Repo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Travis CI
&lt;/h2&gt;

&lt;p&gt;Assuming you have account in Travis CI using your Github account gives Travis CI access to the github repos. Select the "docker-react-app" from the list of repos and switch it on as shown in the snapshot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lKZdZZHr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/sEvMdBc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lKZdZZHr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/sEvMdBc.png" alt="TravisCI"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that Travis CI and Github are hooked up, we need a YML file called .travis.yml to be added in the application as this would contain the instructions you want Travis to perform with the code when the build is triggered.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo: required
language: generic
services:
  - docker

before_install:
  - docker build -t hozefam/docker-react-app -f Dockerfile.dev .

script:
  - docker run -e CI=true hozefam/docker-react-app npm run test
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  AWS - Elasticbeanstalk and S3 bucket
&lt;/h2&gt;

&lt;h3&gt;
  
  
  AWS EBS - Elasticbeanstalk
&lt;/h3&gt;

&lt;p&gt;AWS Elastic Beanstalk is an easy-to-use service for deploying and scaling web applications and services developed with Java, .NET, PHP, Node.js, Python, Ruby, Go, and Docker on familiar servers such as Apache, Nginx, Passenger, and IIS.&lt;/p&gt;

&lt;p&gt;Navigate to the Elasticbeanstalk service on AWS console&lt;br&gt;
Click on "Create Application", set the application name as "docker-react-app" and Platform as "Docker". Leave the other values as default and click on "Create application"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2YgJjjhu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/iF6BTCQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2YgJjjhu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/iF6BTCQ.png" alt="Create a web app"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;after a small pause (approximately 2-3 minutes) you should be able to see a screen like below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GdwSQp_p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/ree9BFz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GdwSQp_p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/ree9BFz.png" alt="EBS"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  AWS IAM
&lt;/h3&gt;

&lt;p&gt;Create a user &lt;strong&gt;travis-docker-react-app&lt;/strong&gt; with programmatic access. Set permissions using &lt;strong&gt;Attach existing polices directly&lt;/strong&gt; option and select &lt;strong&gt;AWSElasticBeanstalkFullAccess&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the last step you will see the &lt;strong&gt;access key id&lt;/strong&gt; and &lt;strong&gt;Secret access key&lt;/strong&gt;. Please note these values and keep it safe, we will use it in Travis CI settings in next step.&lt;/p&gt;
&lt;h3&gt;
  
  
  AWS S3 Buckets
&lt;/h3&gt;

&lt;p&gt;Navigate to S3 Service and depending on the region of the EBS create a folder in the appropriate S3 bucket. Name of the folder should be same as the app name &lt;strong&gt;docker-react-app&lt;/strong&gt; in this case.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TS3n_r0A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/ID9kOye.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TS3n_r0A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/ID9kOye.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Travis CI (again)
&lt;/h2&gt;

&lt;p&gt;In the Travis CI settings for the docker-react-app add the below environment keys &lt;strong&gt;AWS_ACCESS_KEY&lt;/strong&gt; and &lt;strong&gt;AWS_SECRET_KEY&lt;/strong&gt; with the values we stored from the AWS IAM user &lt;strong&gt;travis-docker-react-app&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ufuK3K6l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/4KMEHQC.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ufuK3K6l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/4KMEHQC.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Back to .travis.yml
&lt;/h2&gt;

&lt;p&gt;Add the following step at the end of .travis.yml filee&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;deploy:
  provider: elasticbeanstalk
  region: us-east-1
  app: docker-react-app
  env: DockerReactApp-env
  bucket_name: elasticbeanstalk-us-east-1-534906124127
  bucket_path: docker-react-app
  on:
    branch: master
  access_key_id: $AWS_ACCESS_KEY
  secret_access_key: $AWS_SECRET_KEY
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The complete .travis.yml file should be as&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo: required
language: generic
services:
  - docker

before_install:
  - docker build -t hozefam/docker-react-app -f Dockerfile.dev .

script:
  - docker run -e CI=true hozefam/docker-react-app npm run test

deploy:
  provider: elasticbeanstalk
  region: us-east-1
  app: docker-react-app
  env: DockerReactApp-env
  bucket_name: elasticbeanstalk-us-east-1-534906124127
  bucket_path: docker-react-app
  on:
    branch: master
  access_key_id: $AWS_ACCESS_KEY
  secret_access_key: $AWS_SECRET_KEY
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now checkin the file to github and ensure Travis CI build kicks off&lt;/p&gt;

&lt;p&gt;If all goes good, the react app will be live at the EBS url like this &lt;/p&gt;

&lt;p&gt;&lt;a href="http://dockerreactapp-env.eba-qy3tgb3f.us-east-1.elasticbeanstalk.com/"&gt;http://dockerreactapp-env.eba-qy3tgb3f.us-east-1.elasticbeanstalk.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zfz9sPHN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/lFqzgSD.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zfz9sPHN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/lFqzgSD.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Congrats you have successfully created a production grade workflow.
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Complete Source code can be found &lt;a href="https://github.com/hozefam/docker-react-app"&gt;here&lt;/a&gt;
&lt;/h2&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Travis Docs - &lt;a href="https://docs.travis-ci.com/"&gt;https://docs.travis-ci.com/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Using docker in builds - &lt;a href="https://docs.travis-ci.com/user/docker/"&gt;https://docs.travis-ci.com/user/docker/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Create React App - &lt;a href="https://reactjs.org/docs/create-a-new-react-app.html"&gt;https://reactjs.org/docs/create-a-new-react-app.html&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  NOTE: If you don't want to incurr the AWS costs be sure that the EBS application is deleted.
&lt;/h3&gt;

</description>
      <category>react</category>
      <category>aws</category>
      <category>travis</category>
      <category>docker</category>
    </item>
  </channel>
</rss>
