<?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: Giuseppe Zileni</title>
    <description>The latest articles on DEV Community by Giuseppe Zileni (@gzileni).</description>
    <link>https://dev.to/gzileni</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%2F100345%2F4460dd55-de38-4eb0-af9b-0648c469b6ee.jpg</url>
      <title>DEV Community: Giuseppe Zileni</title>
      <link>https://dev.to/gzileni</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gzileni"/>
    <language>en</language>
    <item>
      <title>whitelistcors</title>
      <dc:creator>Giuseppe Zileni</dc:creator>
      <pubDate>Fri, 15 Jan 2021 11:56:42 +0000</pubDate>
      <link>https://dev.to/gzileni/whitelistcors-28nc</link>
      <guid>https://dev.to/gzileni/whitelistcors-28nc</guid>
      <description>&lt;p&gt;&lt;a href="https://developer.mozilla.org/it/docs/Web/HTTP/CORS"&gt;CORS ( Cross-Origin Resource Sharing)&lt;/a&gt; is a mechanism that allows you to control the sources of requests on a Web page, which is particularly useful for defining security policies on your server, so that a browser and server interact to determine whether it is safe to allow cross-origin request.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--T2kCyFAO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cnwq1cxq9gogh0jbxs8c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--T2kCyFAO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cnwq1cxq9gogh0jbxs8c.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://gzileni.github.io/whitelistcors/"&gt;whitelistcors&lt;/a&gt; module helps developers configure CORS with a &lt;a href="https://nodejs.org/en/"&gt;NodeJS&lt;/a&gt; and &lt;a href="http://expressjs.com/"&gt;ExpressJS&lt;/a&gt; server and is very easy to use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save whitelistcors
yarn add whitelistcors
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To enable a resource to a specific request from an HTTP source, you must implement only an array of addresses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var whitelist = require('whitelistcors');

// lists of origin domains
var origins = ['http://localhost', 'http://mysite.com'];

app.post('/myapi', whitelist(origins), function(req, res, next) {
    res.send('CORS OK!');
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;GitHub Projects: &lt;a href="https://gzileni.github.io/whitelistcors/"&gt;https://gzileni.github.io/whitelistcors/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>express</category>
      <category>npm</category>
    </item>
    <item>
      <title>Flask Bootstrap</title>
      <dc:creator>Giuseppe Zileni</dc:creator>
      <pubDate>Mon, 11 Jan 2021 14:37:53 +0000</pubDate>
      <link>https://dev.to/gzileni/flask-bootstrap-5444</link>
      <guid>https://dev.to/gzileni/flask-bootstrap-5444</guid>
      <description>&lt;p&gt;&lt;a href="https://flask.palletsprojects.com/en/1.1.x/"&gt;Flask&lt;/a&gt; is very simple to use to create REST APIs with Python even with a single file. The repository &lt;a href="//gzileni.github.io/flask-bootstrap/"&gt;flask-bootstrap&lt;/a&gt; is a template to start developing more complex applications with Flask.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EUZwXVd7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/spgtlvt3t5o3t8o2183q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EUZwXVd7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/spgtlvt3t5o3t8o2183q.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's start with the configuration file config.py:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Config(object):
  pass

class ProdConfig(Config):
  pass

class DevConfig(Config):
  DEBUG = True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The root file main.py with ENDPOINT:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask
from config import DevConfig

app = Flask(__name__)
app.config.from_object(DevConfig)

@app.route('/')
def home():
  return '&amp;lt;h1&amp;gt;Hello World!&amp;lt;/h1&amp;gt;'

if __name__ == '__main__':
  app.run()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The template is a simple REST API Server with an ENDPOINT '/' to display the classic "Hello World!" in the browser at the address to &lt;a href="http://127.0.0.1:5000"&gt;http://127.0.0.1:5000&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The project is structured as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dockerfile: Instructions for applying with Flask in a docker container&lt;/li&gt;
&lt;li&gt;requirements.txt: Application dependencies&lt;/li&gt;
&lt;li&gt;/venv: Developmental python environment&lt;/li&gt;
&lt;li&gt;.gitignore: Files to exclude in commits for Git&lt;/li&gt;
&lt;li&gt;main.py: The main file&lt;/li&gt;
&lt;li&gt;config.py: Application configuration&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To run the first flask project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/gzileni/flask-bootstrap.git
cd flask-bootstrap

pip install -r requirements.txt
export FLASK_APP=main.py
flask run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An easy way to run and share the application with the team and send it to production is by using &lt;a href="https://docs.docker.com/get-docker/"&gt;Docker&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker build -t flask-bootstrap .
docker run -p 5000:5000 flask-bootstrap
docker container list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;GitHub Projects: &lt;a href="https://gzileni.github.io/flask-bootstrap/"&gt;https://gzileni.github.io/flask-bootstrap/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>flask</category>
      <category>python</category>
    </item>
    <item>
      <title>logbootstrap</title>
      <dc:creator>Giuseppe Zileni</dc:creator>
      <pubDate>Fri, 08 Jan 2021 16:39:33 +0000</pubDate>
      <link>https://dev.to/gzileni/logbootstrap-1cjg</link>
      <guid>https://dev.to/gzileni/logbootstrap-1cjg</guid>
      <description>&lt;p&gt;During a developer's work on a nodejs application are often used console.log to visualize the progress of code at critical points, for quick debugging, or to display any warnings and errors in your code.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://gzileni.github.io/logbootstrap/"&gt;logbootstrap module&lt;/a&gt; is very simple because it allows you to use colored log messages. The colors available are the same as in the BootStrap tool kit:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;green : successful message&lt;/li&gt;
&lt;li&gt;yellow: for a warning&lt;/li&gt;
&lt;li&gt;cyan: a simple piece of information&lt;/li&gt;
&lt;li&gt;gray: a secondary message&lt;/li&gt;
&lt;li&gt;blue: a very important primary message&lt;/li&gt;
&lt;li&gt;red: error message&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's create a simple nodejs application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mkdir ~/helloworld
$ cd ~/helloword
$ npm init
$ npm install logbootstrap
$ nano index.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the index file.js will be a simple Endpoint API with the most classic "Hello World!"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const http = require('http');
const log = require('logbootstrap);

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) =&amp;gt; {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello, World!\n');
});

server.listen(port, hostname, () =&amp;gt; {
  log('info', 'Server running at http://' + hostname + ':' + port + '/');
  log('success', 'Success log information');
  log('warning', 'Warning log information');
  log('secondary', 'Secondary log information');
  log('primary', 'Primary log information');
  log('danger', 'Danger log information');
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We run the code:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6nfruWWL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1lnyevzwym8km96gg7rg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6nfruWWL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1lnyevzwym8km96gg7rg.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Good Colorful Code !&lt;/p&gt;

&lt;p&gt;GitHub Projects: &lt;a href="https://gzileni.github.io/logbootstrap/"&gt;https://gzileni.github.io/logbootstrap/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
