title: How to add CORS middleware in shelf with router?
body: <p>I am new to server side programming with dart. I made a simple API server with a number of get routes. I am handling this as follow,</p>
  <pre><code>  Router router = Router();
  
    router.get('/', checkSTATUS);
  
    router.get('/login/&lt;user&gt;/&lt;pass&gt;', (Request request, String user, String pass) async {
     id = 0;
      // stuff
        return Response.ok(json.encode({&quot;status&quot;:&quot;found&quot;,&quot;id&quot;:id}));
      
     
    });
  
    router.get('/update', (Request request) async {
        //stuff
        return Response.ok(json.encode({&quot;status&quot;: &quot;updated&quot;, &quot;data&quot;: updated}));
      
  
    });
  
  //for any other requests
    router.all('/&lt;ignored|.*&gt;', (Request request) {
        return Response.notFound(json.encode('Page not found'));
  });
  
    final server = await serve(
      router,
      InternetAddress.anyIPv4,
      8080,
    );
  
  </code></pre>
  <p>I can access these routes using postman but making requests using flutter web results in error. I searched and found out that this may be CORS related. But how do I add the CORS headers without disrupting the entire code.</p>