<?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 Sebastián Vidal Aedo on Medium]]></title>
        <description><![CDATA[Stories by Sebastián Vidal Aedo on Medium]]></description>
        <link>https://medium.com/@sebacode?source=rss-95507395cd0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*xaR10g_dJ7NQcrRxWaU8aw@2x.jpeg</url>
            <title>Stories by Sebastián Vidal Aedo on Medium</title>
            <link>https://medium.com/@sebacode?source=rss-95507395cd0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 16:08:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sebacode/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[Deploy Node/Express backend to AWS EC2]]></title>
            <link>https://sebacode.medium.com/deploy-node-express-backend-to-aws-ec2-9a9f8e7f5222?source=rss-95507395cd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a9f8e7f5222</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[backend-deployment]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[expressjs]]></category>
            <dc:creator><![CDATA[Sebastián Vidal Aedo]]></dc:creator>
            <pubDate>Wed, 17 Apr 2024 03:31:34 GMT</pubDate>
            <atom:updated>2024-04-17T03:31:34.628Z</atom:updated>
            <content:encoded><![CDATA[<p>In this guide, I’ll walk you through the process of deploying a Node.js backend with Express on an AWS EC2 instance. This backend allows CRUD operations on several models and facilitates uploading images and files to S3, hence the presence of AWS configurations in the .env file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eG3mN1hPd3UCvrQu" /></figure><h4>Create an EC2 Instance</h4><blockquote>EC2 (Elastic Compute Cloud): EC2 is a web service provided by Amazon Web Services (AWS) that offers resizable compute capacity in the cloud.</blockquote><p>Navigate to the AWS console and create an EC2 instance. I typically opt for an Ubuntu Server in the free tier, but you can choose any suitable option.</p><h4>Connect to the Instance</h4><p>Once your instance is up and running, connect to it using your preferred method. I find it convenient to save the configuration in my ~/.ssh/config file. Here&#39;s an example:</p><pre>Host my-ec2<br>  HostName ec2-3-23-23-23.compute-1.amazonaws.com<br>  User ubuntu<br>  IdentityFile ~/.ssh/my-key.pem</pre><p>Replace HostName with your instance&#39;s public DNS and IdentityFile with the path to your key. Then, connect using:</p><pre>ssh my-ec2</pre><h4>Set Up RDS Database</h4><blockquote>RDS (Relational Database Service): RDS is a managed database service provided by AWS that makes it easy to set up, operate, and scale relational databases in the cloud. RDS supports several popular database engines such as MySQL, PostgreSQL, Oracle, SQL Server, and MariaDB.</blockquote><p>I utilize an RDS database to store my app’s data. You can create one in the AWS console, and for this project, I use PostgreSQL. Once created, grant appropriate permissions and obtain the connection string containing the user, password, host, port, and database name.</p><h4>Install Dependencies</h4><p>Once connected to the instance, install necessary dependencies. For my setup, I require Node.js, NPM, nvm, nginx, certbot, Git, and PM2. Here’s how to install Node.js and NPM:</p><pre>sudo apt update<br>sudo apt install nodejs nginx git certbot python3-certbot-nginx<br>curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash<br>nvm install lts</pre><p>Generate an SSH key for repository access (optional but recommended):</p><pre>ssh-keygen -t rsa -b 4096 -C &quot;user@mail.com&quot;<br>cat ~/.ssh/id_rsa.pub  # Copy the key and add it to your repo</pre><h4>Clone the Repo and Install the App</h4><p>Once dependencies are installed, clone your app’s repository and install dependencies:</p><pre>git clone git@github.com:user/backend.git backend<br>cd backend<br>npm install</pre><h4>Configure the App</h4><p>Configure your app by creating a .env file. Here&#39;s an example:</p><pre>NODE_ENV=production<br>HOST=http://domain<br>PORT=3000<br><br>DATABASE_URL=postgres://user:pass@host_database:port/database_name<br><br>AWS_ACCESS_KEY_ID=<br>AWS_SECRET_ACCESS_KEY=<br>AWS_S3_REGION=<br>AWS_S3_BUCKET_NAME=<br><br>JWT_SECRET=</pre><p>Configure Nginx</p><ul><li>Configure Nginx to serve your app. Create a configuration file:</li></ul><pre>sudo nano /etc/nginx/sites-available/my-config</pre><p>Add server configurations for your domain and SSL certificate using certbot. Then, restart Nginx:</p><pre>sudo systemctl restart nginx<br>sudo certbot --nginx -d custom-domain.com<br>sudo ln -s /etc/nginx/sites-available/my-config /etc/nginx/sites-enabled/<br>sudo systemctl restart nginx</pre><h4>Route 53</h4><blockquote>Route 53: Route 53 is a scalable and highly available Domain Name System (DNS) web service provided by AWS. It allows users to register domain names and route internet traffic to resources like EC2 instances, load balancers, and S3 buckets.</blockquote><p>If you’re using a custom domain, configure Route 53 to point the domain to the EC2 instance. Create a record in the AWS console and update the nameservers with your domain provider.</p><h4>Run the App</h4><p>Finally, start your app with PM2:</p><blockquote>PM2, or Process Manager 2, is a popular process manager for Node.js applications. It allows you to manage, monitor, and deploy Node.js applications</blockquote><pre>cd backend<br>pm2 start app.js --name my-app</pre><p>For updates, fetch and pull changes from your repo and restart the app:</p><pre>cd backend<br>git fetch &amp;&amp; git pull origin main<br>pm2 restart my-app</pre><p>With these steps, you can successfully deploy your Node.js backend on an AWS EC2 instance. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a9f8e7f5222" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Synchronize 2 databases in postgresql bidirectionally]]></title>
            <link>https://sebacode.medium.com/synchronize-2-databases-in-postgresql-bidirectionally-4adf3c81f4b8?source=rss-95507395cd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/4adf3c81f4b8</guid>
            <category><![CDATA[synchronicity]]></category>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Sebastián Vidal Aedo]]></dc:creator>
            <pubDate>Tue, 28 Nov 2023 01:59:30 GMT</pubDate>
            <atom:updated>2024-07-14T00:40:28.171Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*K8yLE7z1M1u2poMs" /></figure><p>There are several synchronization options, the “challenge” appears when it must be bidirectional synchronization, that is, changes in the database_1 are reflected in database_2 and also when I change something in database_2 are reflected in database_1.</p><p>I’m sure there must be more ways, but this is the solution I managed to implement.</p><p>In summary, and before moving on to the step by step, what I did was: using a Postgres tool (pglogic) I made postgres_node1 (docker with pg) listen for changes in postgres_node2 (another docker with pg) and postgres_node2 listen for changes in postgres_node1 and will replicate them. That’s all.</p><h3>Step by Step</h3><h4>0. Network and Config</h4><p>We need both Dockers to be able to see each other over a network, only then can we synchronize them. For that “we can” create a network.</p><pre>docker network create network_bds</pre><h4>1. The Databases</h4><p><strong>postgres_node1</strong> and <strong>postgres_node2</strong> are the same, they are “dockers” built with the latest Postgres image. They have a user and password based on their names: user1-password1 and user2-password2, but their ports are different (because they are in the same environment) 5432 for node1 and 5433 for node2.</p><p>In addition, below are the <strong><em>sql scripts</em></strong> to create the test database (<strong>publications</strong>), the user and the password. Finally we give the user permissions on the database (we will use it to connect later) and we make the user “SUPERUSER” to work with the pglogical statements.</p><h4>postgres_node1</h4><pre>docker run --name postgres-node1 --network network_bds -e POSTGRES_PASSWORD=password1 -d -p 5432:5432 postgres:latest<br>docker exec -it postgres-node1 psql -U postgres</pre><pre>CREATE USER user1 WITH PASSWORD &#39;password1&#39;;<br>CREATE DATABASE posts;<br><br>\c posts;<br><br>CREATE TABLE publications (<br>  id SERIAL PRIMARY KEY,<br>  title VARCHAR(255),<br>  content TEXT<br>);<br><br>GRANT ALL PRIVILEGES ON DATABASE posts TO user1;<br>GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO user1;<br>ALTER USER user1 WITH SUPERUSER;</pre><h4>postgres_node2</h4><pre>docker run --name postgres-node2 --network network_bds -e POSTGRES_PASSWORD=password2 -d -p 5433:5432 postgres:latest<br>docker exec -it postgres-node2 psql -U postgres</pre><pre>CREATE USER user2 WITH PASSWORD &#39;password2&#39;;<br>CREATE DATABASE posts;<br><br>\c posts;<br><br>CREATE TABLE publications (<br>  id SERIAL PRIMARY KEY,<br>  title VARCHAR(255),<br>  content TEXT<br>);<br><br>GRANT ALL PRIVILEGES ON DATABASE posts TO user2;<br>GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO user2;<br>ALTER USER user2 WITH SUPERUSER;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/282/1*pb7YQbBIiVKhcTTDhXRlng.png" /><figcaption>The two databases created</figcaption></figure><h4>2. PgLogical</h4><p>Install postgresql-15-pglogical (15 depends on the version of pg) and vim (not mandatory, but it is comfortable for me to edit in vim)</p><pre>docker exec -it postgres-node1 bash<br>apt update &amp;&amp; apt upgrade &amp;&amp; apt install -y python3-pip postgresql-15-pglogical vim<br><br>docker exec -it postgres-node2 bash<br>apt update &amp;&amp; apt upgrade &amp;&amp; apt install -y python3-pip postgresql-15-pglogical vim</pre><p>In both containers do the same, it is a necessary configuration so that <strong><em>pglogical</em></strong> can be used</p><pre>vim /var/lib/postgresql/data/postgresql.conf</pre><pre>shared_preload_libraries = &#39;pglogical&#39;<br>wal_level = logical</pre><pre>echo &quot;en_US UTF-8 &quot; &gt;&gt; /etc/locale.gen &amp;&amp; locale-gen</pre><p>Restart pg (or docker)!</p><h4>3. Primary and Secondary</h4><p>Primary on <strong>postgres-node1</strong> and Secondary on <strong>postgres-node2</strong></p><pre>docker exec -it postgres-node1 psql -U postgres</pre><pre>\c posts<br>CREATE EXTENSION pglogical;<br>CREATE EXTENSION IF NOT EXISTS pglogical;<br>SELECT * FROM pg_extension WHERE extname = &#39;pglogical&#39;;<br><br># give permissions to user user1 to do everything<br>GRANT USAGE ON SCHEMA pglogical TO user1;<br>GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA pglogical TO user1;<br>GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA pglogical TO user1;<br><br>SELECT pglogical.create_node(node_name := &#39;node1&#39;, dsn := &#39;host=postgres-node1 dbname=posts port=5432 user=user1 password=password1&#39;);<br>SELECT pglogical.replication_set_add_table(&#39;default&#39;, &#39;publications&#39;);</pre><pre>docker exec -it postgres-node2 psql -U postgres</pre><pre>\c posts<br>CREATE EXTENSION pglogical;<br>SELECT pglogical.create_node(node_name := &#39;node2&#39;, dsn := &#39;host=postgres-node2 dbname=posts user=user2 password=password2&#39;);<br>SELECT pglogical.create_subscription(subscription_name := &#39;node1_subscription&#39;, provider_dsn := &#39;host=postgres-node1 dbname=posts user=user1 password=password1&#39;);</pre><p>Now we do the opposite, we leave primary to <strong>postgres-node2</strong> and secondary to <strong>postgres-node1</strong></p><pre>docker exec -it postgres-node2 psql -U postgres</pre><pre>\c posts<br>SELECT pglogical.replication_set_add_table(&#39;default&#39;, &#39;publications&#39;);</pre><pre>docker exec -it postgres-node1 psql -U postgres</pre><pre>\c posts<br>SELECT pglogical.create_subscription(subscription_name := &#39;node2_subscription&#39;, provider_dsn := &#39;host=postgres-node2 dbname=posts user=user2 password=password2 port=5433&#39;);</pre><p>And…. It’s works!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4adf3c81f4b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build an environment to work with Laravel using Docker]]></title>
            <link>https://sebacode.medium.com/build-an-environment-to-work-with-laravel-using-docker-2fbe77f21cf5?source=rss-95507395cd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/2fbe77f21cf5</guid>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Sebastián Vidal Aedo]]></dc:creator>
            <pubDate>Mon, 15 May 2023 14:24:10 GMT</pubDate>
            <atom:updated>2023-05-15T14:24:10.598Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://laravel.com/">Laravel</a> is widely recognized as the best PHP framework and in this post I will show you how you can set up a development environment for Laravel projects using Docker Compose and PostgreSQL. The main idea is to use Docker to provide us with a database, a web server and all the necessary dependencies, thus reducing compatibility and local versioning issues. With this approach, you will be able to quickly set up a consistent development environment ready to start developing your Laravel project without worrying about the usual complications.</p><h4>Create the directory and install Laravel</h4><p>As in any project, the first thing we need to do is to create a base directory. In this case, we will call it “laravel_project”. Once inside the project directory, we will use Composer to download and install Laravel. Composer is an essential tool in the Laravel ecosystem, as it allows us to manage dependencies easily and efficiently. Next, I will show you the necessary steps to perform this installation.</p><pre>mkdir laravel_project<br>cd laravel_project/<br>composer create-project --prefer-dist laravel/laravel .</pre><h4>Docker</h4><p>Using Docker, and more specifically Docker Compose, we will configure and set up our development environment, which will include the web server and database needed for our Laravel project. Below, I will show you a configuration file:</p><pre>version: &#39;3.8&#39;<br>services:<br>  app:<br>    image: php:8.0-apache<br>    container_name: laravel-app<br>    volumes:<br>      - ./laravel-app:/var/www/html<br>    ports:<br>      - 8000:8000<br>    networks:<br>      - laravel<br>    depends_on:<br>      - db<br><br>  db:<br>    image: postgres:13<br>    container_name: postgres-db<br>    restart: always<br>    environment:<br>      POSTGRES_DB: laravel<br>      POSTGRES_USER: postgres<br>      POSTGRES_PASSWORD: postgres<br>    volumes:<br>      - db_data:/var/lib/postgresql/data<br>    networks:<br>      - laravel<br><br>volumes:<br>  db_data:<br><br>networks:<br>  laravel:</pre><p>With this we raise 2 containers that see each other (they are in the same container-level network called <strong><em>laravel</em></strong>). One for the application (<strong>laravel-app</strong>) which links the current directory to a directory on a server in the internal path of the container in /var/www/html and which exposes its content on port 8080. The other container that is built is the database (<strong>postgres-db</strong>), which includes the setting of its access variables such as user, pass and database name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*ZKHNE_xJZ-nXF5sWbYnm1A.png" /></figure><h4>Last steps before we start programming</h4><p>Before we dive into programming, there are a couple of additional tasks we need to complete. First, we need to generate the Laravel key by running the following command.</p><pre>php artisan key:generate</pre><p>In addition, we must complete the <strong>.env</strong> file with the necessary variables to access the database.</p><pre>APP_NAME=Laravel<br>APP_ENV=local<br>APP_KEY=the_key_generated<br>APP_DEBUG=true<br>APP_URL=http://localhost<br><br>LOG_CHANNEL=stack<br>LOG_DEPRECATIONS_CHANNEL=null<br>LOG_LEVEL=debug<br><br>DB_CONNECTION=pgsql<br>DB_HOST=127.0.0.1<br>DB_PORT=5432<br>DB_DATABASE=laravel<br>DB_USERNAME=postgres<br>DB_PASSWORD=postgres<br><br>BROADCAST_DRIVER=log<br>CACHE_DRIVER=file<br>FILESYSTEM_DISK=local<br>QUEUE_CONNECTION=sync<br>SESSION_DRIVER=file<br>SESSION_LIFETIME=120<br><br>MEMCACHED_HOST=127.0.0.1<br><br>REDIS_HOST=127.0.0.1<br>REDIS_PASSWORD=null<br>REDIS_PORT=6379<br><br>MAIL_MAILER=smtp<br>MAIL_HOST=mailpit<br>MAIL_PORT=1025<br>MAIL_USERNAME=null<br>MAIL_PASSWORD=null<br>MAIL_ENCRYPTION=null<br>MAIL_FROM_ADDRESS=&quot;hello@example.com&quot;<br>MAIL_FROM_NAME=&quot;${APP_NAME}&quot;<br><br>AWS_ACCESS_KEY_ID=<br>AWS_SECRET_ACCESS_KEY=<br>AWS_DEFAULT_REGION=us-east-1<br>AWS_BUCKET=<br>AWS_USE_PATH_STYLE_ENDPOINT=false<br><br>PUSHER_APP_ID=<br>PUSHER_APP_KEY=<br>PUSHER_APP_SECRET=<br>PUSHER_HOST=<br>PUSHER_PORT=443<br>PUSHER_SCHEME=https<br>PUSHER_APP_CLUSTER=mt1<br><br>VITE_PUSHER_APP_KEY=&quot;${PUSHER_APP_KEY}&quot;<br>VITE_PUSHER_HOST=&quot;${PUSHER_HOST}&quot;<br>VITE_PUSHER_PORT=&quot;${PUSHER_PORT}&quot;<br>VITE_PUSHER_SCHEME=&quot;${PUSHER_SCHEME}&quot;<br>VITE_PUSHER_APP_CLUSTER=&quot;${PUSHER_APP_CLUSTER}&quot;</pre><p>Once this is done, we just need to create and launch the containers</p><pre>docker compose up -d</pre><p>and then start our project</p><pre>php artisan serve</pre><p>If we access 127.0.0.1:8080, we will be ready to start programming.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2WCs7kYE07jAGR9N19SMKw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2fbe77f21cf5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to document a Node.js API with Swagger]]></title>
            <link>https://sebacode.medium.com/how-to-document-a-node-js-api-with-swagger-554101246a4d?source=rss-95507395cd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/554101246a4d</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[swagger]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Sebastián Vidal Aedo]]></dc:creator>
            <pubDate>Fri, 12 May 2023 03:52:19 GMT</pubDate>
            <atom:updated>2023-05-12T03:52:19.825Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://swagger.io/">Swagger</a> is an open-source software framework that helps developers design, build, document, and consume RESTful web services. It provides a set of tools that enable developers to describe the structure of APIs in a standard way, making it easier to understand and consume them. Swagger allows developers to create API documentation that is both machine-readable and human-friendly, making it easier to communicate with other developers and stakeholders.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T60lDIwi6_lGkwSbiFUXsQ.png" /></figure><h3>How we can add it to your project?</h3><p>First of all, this example will use a dummy model, called <strong>Publication</strong>, which consists of 2 attributes: <strong>name</strong> and <strong>content</strong>.</p><h4>Installation</h4><p>Make sure you have both swagger-ui-express and swagger-jsdoc installed in your Node.js project:</p><pre>npm install swagger-ui-express swagger-jsdoc</pre><h4>Configuration</h4><p>Create a file named app.js and add the following code:</p><pre>const express = require(&#39;express&#39;);<br>const swaggerUi = require(&#39;swagger-ui-express&#39;);<br>const swaggerJsDoc = require(&#39;swagger-jsdoc&#39;);<br><br>const app = express();<br><br>// Swagger configuration options<br>const swaggerOptions = {<br>  swaggerDefinition: {<br>    info: {<br>      title: &#39;Publication API&#39;,<br>      description: &#39;CRUD API for managing publications&#39;,<br>      version: &#39;1.0.0&#39;,<br>    },<br>  },<br>  apis: [&#39;./routes/*.js&#39;], // Path to the API routes folder<br>};<br><br>const swaggerDocs = swaggerJsDoc(swaggerOptions);<br>app.use(&#39;/api-docs&#39;, swaggerUi.serve, swaggerUi.setup(swaggerDocs));<br><br>// Routes<br>app.use(&#39;/publications&#39;, require(&#39;./routes/publications&#39;));<br><br>// Start the server<br>app.listen(3000, () =&gt; {<br>  console.log(&#39;Server running on port 3000&#39;);<br>});</pre><h4>Documentation</h4><p>Create a folder named routes in the same directory as app.js. Inside the routes folder, create a file named publications.js and add the following code:</p><pre>const express = require(&#39;express&#39;);<br>const router = express.Router();<br><br>/**<br> * @swagger<br> * /publications:<br> *   get:<br> *     summary: Get all publications<br> *     responses:<br> *       200:<br> *         description: Returns all publications<br> */<br>router.get(&#39;/&#39;, (req, res) =&gt; {<br>  // Implementation for getting all publications<br>});<br><br>/**<br> * @swagger<br> * /publications/{id}:<br> *   get:<br> *     summary: Get a publication by ID<br> *     parameters:<br> *       - in: path<br> *         name: id<br> *         required: true<br> *         schema:<br> *           type: string<br> *         description: Publication ID<br> *     responses:<br> *       200:<br> *         description: Returns the publication with the specified ID<br> *       404:<br> *         description: Publication not found<br> */<br>router.get(&#39;/:id&#39;, (req, res) =&gt; {<br>  // Implementation for getting a publication by ID<br>});<br><br>/**<br> * @swagger<br> * /publications:<br> *   post:<br> *     summary: Create a new publication<br> *     parameters:<br> *       - in: body<br> *         name: publication<br> *         required: true<br> *         schema:<br> *           type: object<br> *           properties:<br> *             name:<br> *               type: string<br> *             content:<br> *               type: string<br> *         description: Publication object<br> *     responses:<br> *       201:<br> *         description: Publication created successfully<br> */<br>router.post(&#39;/&#39;, (req, res) =&gt; {<br>  // Implementation for creating a new publication<br>});<br><br>/**<br> * @swagger<br> * /publications/{id}:<br> *   put:<br> *     summary: Update a publication by ID<br> *     parameters:<br> *       - in: path<br> *         name: id<br> *         required: true<br> *         schema:<br> *           type: string<br> *         description: Publication ID<br> *       - in: body<br> *         name: publication<br> *         required: true<br> *         schema:<br> *           type: object<br> *           properties:<br> *             name:<br> *               type: string<br> *             content:<br> *               type: string<br> *         description: Updated publication object<br> *     responses:<br> *       200:<br> *         description: Publication updated successfully<br> *       404:<br> *         description: Publication not found<br> */<br>router.put(&#39;/:id&#39;, (req, res) =&gt; {<br>  // Implementation for updating a publication by ID<br>});<br><br>/**<br> * @swagger<br> * /publications/{id}:<br> *   delete:<br> *     summary: Delete a publication by ID<br> *     parameters:<br> *       - in: path<br> *         name: id<br> *         required: true<br> *         schema:<br> *           type: string<br> *         description: Publication ID<br> *     responses:<br> *       200:<br> *         description: Publication deleted successfully<br> *       404:<br> *         description: Publication not found<br> */<br>router.delete(&#39;/:id&#39;, (req, res) =&gt; {<br>  // Implementation for deleting a publication by ID<br>});<br><br>module.exports = router;</pre><p>That’s it! You now have a basic implementation of swagger-ui-express and swagger-jsdoc to document a CRUD API for the &quot;Publication&quot; object. You can start the server by running node app.js, and then access the Swagger UI documentation at <a href="http://localhost:3000/api-docs.">http://localhost:3000/api-docs.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=554101246a4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Edit and Organize Your Commits with Git Interactive Rebase]]></title>
            <link>https://sebacode.medium.com/edit-and-organize-your-commits-with-git-interactive-rebase-244aa60e217b?source=rss-95507395cd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/244aa60e217b</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[code-quality]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[version-control]]></category>
            <category><![CDATA[git-workflow]]></category>
            <dc:creator><![CDATA[Sebastián Vidal Aedo]]></dc:creator>
            <pubDate>Sat, 06 May 2023 23:58:24 GMT</pubDate>
            <atom:updated>2023-05-06T23:58:24.327Z</atom:updated>
            <content:encoded><![CDATA[<h4>Git rebase interactive is a tool that allows you to edit and rebase commits in your Git history in an interactive way…</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*D1TaR7wsah4npO9nR0zNeQ.jpeg" /></figure><p>Yeah, but why i’m going to need it? Imagine your <strong>git log</strong> look something like this:</p><pre>commit e47d1a8b08c9f59e1b662f6b57f26383b67f37f5 (HEAD -&gt; master)<br>Author: John Doe &lt;johndoe@example.com&gt;<br>Date:   Thu May 5 12:00:00 2023 -0400<br><br>    Final commit<br><br>commit 37f48de4100e157e42d8283d3c8cc7fcd6a0c68b<br>Author: John Doe &lt;johndoe@example.com&gt;<br>Date:   Wed May 4 15:00:00 2023 -0400<br><br>    Add feature X<br><br>commit 12093df4a78d4b84f05c1fb2a1cfcf10ba86a9c9<br>Author: John Doe &lt;johndoe@example.com&gt;<br>Date:   Tue May 3 10:00:00 2023 -0400<br><br>    Fix bug in feature Y<br><br>commit f85e2d5c1966ca71755cbbd72f47bf3323e0103a<br>Author: John Doe &lt;johndoe@example.com&gt;<br>Date:   Mon May 2 09:00:00 2023 -0400<br><br>    Add feature Y<br><br>commit 74d1c5bbf7b6ca936e6d3b36e3c41e3de01f2425<br>Author: John Doe &lt;johndoe@example.com&gt;<br>Date:   Sun May 1 08:00:00 2023 -0400<br><br>    Initial commit</pre><p>You don’t want to share or deliver as a final software product “something” with that log where it can (badly) show a low quality when committing code.</p><p>To fix this we use <strong>Git Interactive Rebase</strong>.</p><p>Continuing the example, let’s imagine we want the following: each commit has a sequential text as content (just for the example, in a real case it should be different) and also, we want to merge the last 2 commits into only 1.</p><pre>git rebase -i HEAD~5</pre><p>In this case, <strong>HEAD~5</strong> indicates that the last 5 commits before the current commit will be included, that is, the last 5 commits in the current branch at the position of the HEAD pointer will be included.</p><p>With the previous command, an interactive window will be displayed where you can edit the commits. Something like this:</p><pre>pick 74d1c5b Initial commit<br>pick f85e2d5 Add feature Y<br>pick 12093df Fix bug in feature Y<br>pick 37f48de Add feature X<br>pick e47d1a8 Final commit</pre><p>To rename commits sequentially, change the word “pick” to the letter “r” (which stands for “reward”). It should look like this:</p><pre>r 74d1c5b Initial commit<br>r f85e2d5 Add feature Y<br>r 12093df Fix bug in feature Y<br>r 37f48de Add feature X<br>r e47d1a8 Final commit</pre><p>After saving, we will see windows to update each of the commit messages by updating the commit text (example: commit 1, 2, 3….). We do a</p><pre>git rebase --continue</pre><p>and finish the process.</p><p>Now, when we do <strong>git log</strong> we will see something like this:</p><pre>commit e47d1a8b08c9f59e1b662f6b57f26383b67f37f5 (HEAD -&gt; master)<br>Author: John Doe &lt;johndoe@example.com&gt;<br>Date:   Thu May 5 12:00:00 2023 -0400<br><br>    Commit 5<br><br>commit 37f48de4100e157e42d8283d3c8cc7fcd6a0c68b<br>Author: John Doe &lt;johndoe@example.com&gt;<br>Date:   Wed May 4 15:00:00 2023 -0400<br><br>    Commit 4<br><br>commit 12093df4a78d4b84f05c1fb2a1cfcf10ba86a9c9<br>Author: John Doe &lt;johndoe@example.com&gt;<br>Date:   Tue May 3 10:00:00 2023 -0400<br><br>    Commit 3<br><br>commit f85e2d5c1966ca71755cbbd72f47bf3323e0103a<br>Author: John Doe &lt;johndoe@example.com&gt;<br>Date:   Mon May 2 09:00:00 2023 -0400<br><br>    Commit 2<br><br>commit 74d1c5bbf7b6ca936e6d3b36e3c41e3de01f2425<br>Author: John Doe &lt;johndoe@example.com&gt;<br>Date:   Sun May 1 08:00:00 2023 -0400<br><br>    Commit 1</pre><p>Finally, to merge the last 2 commits we do:</p><pre>git rebase -i HEAD~2</pre><pre>pick 37f48de Commit 4<br>pick e47d1a8 Commit 5</pre><p>change <strong>pick</strong> for <strong>squash</strong></p><pre>pick 37f48de Commit 4<br>s e47d1a8 Commit 5</pre><p>Then save and close the interactive window. Another window will open so you can edit the resulting commit message. Make sure the message adequately describes the changes made.</p><p>When you save and close this window, Git will merge the two commits and show you the result in the commit log. The commit log will look like this:</p><pre>commit eec98e92e714f44955f7b66e238fb2e025aa1d12 (HEAD -&gt; master)<br>Author: John Doe &lt;johndoe@example.com&gt;<br>Date:   Thu May 5 12:00:00 2023 -0400<br><br>    Commit 5<br><br>    Commit 4<br><br>commit 12093df4a78d4b84f05c1fb2a1cfcf10ba86a9c9<br>Author: John Doe &lt;johndoe@example.com&gt;<br>Date:   Tue May 3 10:00:00 2023 -0400<br><br>    Commit 3<br><br>commit f85e2d5c1966ca71755cbbd72f47bf3323e0103a<br>Author: John Doe &lt;johndoe@example.com&gt;<br>Date:   Mon May 2 09:00:00 2023 -0400<br><br>    Commit 2<br><br>commit 74d1c5bbf7b6ca936e6d3b36e3c41e3de01f2425<br>Author: John Doe &lt;johndoe@example.com&gt;<br>Date:   Sun May 1 08:00:00 2023 -0400<br><br>    Commit 1</pre><p>As you can see, commits 4 and 5have been merged into a single commit called “Commit 5 - Commit 4”. The hash of commit 5 has also changed due to the change in its history.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=244aa60e217b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Git Rebase: Solving Problems and Streamlining Workflows]]></title>
            <link>https://sebacode.medium.com/git-rebase-solving-problems-and-streamlining-workflows-9e634575f33d?source=rss-95507395cd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e634575f33d</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[git-rebase]]></category>
            <category><![CDATA[coding-tips]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Sebastián Vidal Aedo]]></dc:creator>
            <pubDate>Sat, 25 Mar 2023 21:16:25 GMT</pubDate>
            <atom:updated>2023-03-25T21:16:25.560Z</atom:updated>
            <content:encoded><![CDATA[<h4>Git rebase streamlines workflows and solves branch problems. In this article, we’ll cover its basics and how to use it effectively for a cleaner project structure and more efficient Git work.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*SG2zMzENLAMztd2SX7xzBQ.png" /></figure><h3>What is git rebase?</h3><p>Git rebase is an operation in Git that allows a branch to be moved to a new base. This means it rearranges the history of changes in a branch so that it begins from a different point than its current base. This is achieved by applying the changes of one branch to a different base, instead of merging two branches.</p><p>Unlike other operations like merge and cherry-pick, git rebase preserves the linear history of the branch, meaning changes are applied one after the other in chronological order. This helps maintain a clear and easy-to-follow history of changes, especially in projects with multiple collaborators.</p><p>In practice, git rebase can be useful in situations such as when you want to update a branch with the latest changes from another branch, or when you want to maintain a clearer and more organized history of changes. For example, instead of merging a branch with another and creating an additional merge commit, git rebase can be used to apply the changes of the branch to the new base and maintain a linear and easy-to-follow history of changes.</p><h3>Why use git rebase?</h3><p>Git rebase solves several problems that may arise when working with Git branches. For example, it helps to avoid creating unnecessary merge commits that can clutter the history of changes and make it difficult to follow. It also helps to keep the branch history linear and maintain a cleaner and more organized project structure.</p><p>Some advantages of using git rebase include:</p><ul><li>Creating a cleaner and more linear branch history</li><li>Maintaining a clear and easy-to-follow project structure</li><li>Avoiding unnecessary merge commits that can clutter the branch history</li><li>Keeping changes in chronological order, making it easier to understand the history of changes</li></ul><p>However, it’s important to note that git rebase may not always be the best option in every situation. Some potential disadvantages of using git rebase include the risk of losing commits and changes if not done correctly, and the potential for conflicts to arise when rebasing changes from different branches. Therefore, it’s important to carefully consider the specific needs of your project and consult best practices before using git rebase.</p><h3>How to use git rebase in practice</h3><p>Using git rebase in practice involves several steps, which may vary depending on the specific use case. Some general steps for using git rebase include:</p><ol><li>Identify the branch to rebase and the new base branch.</li><li>Use the git rebase command to apply the changes of the rebased branch to the new base branch.</li><li>Resolve any conflicts that arise during the rebase process.</li><li>Test the rebased changes to ensure they work as expected.</li><li>Commit and push the rebased changes to the remote repository.</li></ol><p>It’s important to note that using git rebase can be a complex process, and it’s important to follow best practices and consult documentation and tutorials before attempting to use it. Additionally, it’s recommended to use version control tools such as Git GUI clients or IDEs that provide built-in support for git rebase.</p><h3>Let’s get to work</h3><p>Assuming you have a local Git repository with at least two branches (the branch to rebase and the new base branch), here are some general steps to perform a git rebase:</p><p>1. First, ensure that you are on the branch that you want to rebase. For example, if you want to rebase the feature-branch onto main, run the following command to switch to feature-branch:</p><pre>git checkout feature-branch</pre><p>2. Next, run the git rebase command with the new base branch as the argument. For example, to rebase feature-branch onto main, run the following command:</p><pre>git rebase main</pre><p>3. If there are any conflicts during the rebase process, Git will prompt you to resolve them. Use a text editor to resolve any conflicts in the affected files and save the changes.</p><p>4. After resolving any conflicts, run the following command to continue the rebase process:</p><pre>git rebase --continue</pre><p>5. If there are still conflicts, repeat steps 3–4 until all conflicts are resolved.</p><p>6. Finally, push the rebased changes to the remote repository using the following command:</p><pre>git push --force-with-lease</pre><p>Note that the --force-with-lease option is required when pushing rebased changes to the remote repository because the rebased branch has a different history than the original branch. It&#39;s important to use this option instead of --force, which can overwrite changes made by other collaborators.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e634575f33d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Delete all branches except main / master]]></title>
            <link>https://sebacode.medium.com/delete-all-branches-except-main-master-4758bc00492d?source=rss-95507395cd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/4758bc00492d</guid>
            <category><![CDATA[main-branch]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[git-tips]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[simplify-history]]></category>
            <dc:creator><![CDATA[Sebastián Vidal Aedo]]></dc:creator>
            <pubDate>Sat, 11 Mar 2023 17:06:05 GMT</pubDate>
            <atom:updated>2023-03-11T17:06:05.755Z</atom:updated>
            <content:encoded><![CDATA[<p>Deleting all branches of a Git project can be a useful task when you want to simplify the history of a project or when you need to maintain only the main branch. Fortunately, Git provides an easy way to do this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*EcWHP6mrDBshXBWgOZA7lg.jpeg" /></figure><p>First, to ensure that we have a backup of all our branches, we must make a local backup of our repository. Then, we can use the following command in the terminal to delete all branches except the main one:</p><pre>git branch | grep -v &quot;main&quot; | xargs git branch -D</pre><p>This command lists <strong>all the branches</strong> of the project, excluding the main branch, and deletes them. This way, only the main branch will be kept in the project.</p><p>It’s important to note that once the branches are deleted, <strong>they cannot be recovered</strong>, so make sure to backup before running this command.</p><h4>Useful?</h4><p>Yes, deleting all branches of a Git project is a useful task in specific situations, such as when you need to simplify the project history or when you need to maintain only the main branch. Although it’s not something that is done regularly, it can be an effective solution in cases where the repository has become disorganized and needs to be cleaned up.</p><p>In summary, it’s a technique that is used occasionally and in specific situations.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4758bc00492d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Easy blog using Eleventy]]></title>
            <link>https://sebacode.medium.com/easy-blog-using-eleventy-8187b7547ff4?source=rss-95507395cd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/8187b7547ff4</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[eleventy]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[static-site-generator]]></category>
            <dc:creator><![CDATA[Sebastián Vidal Aedo]]></dc:creator>
            <pubDate>Mon, 06 Mar 2023 05:51:56 GMT</pubDate>
            <atom:updated>2023-03-06T05:51:56.108Z</atom:updated>
            <content:encoded><![CDATA[<p>I like the idea of using static sites for personal blogs or sites that don’t require frequent updates or a large team to manage content. Although I currently use Jekyll for thebeerbrother.cl, during my search for a JavaScript alternative, I came across Eleventy, which surprised me with its simplicity and the many “automatic” or “conventional” things it does. I’ll be using it for an upcoming project :). Now, let me show you how to install and use it.</p><h3>Go to Eleventy</h3><p><a href="https://www.11ty.dev/">Eleventy</a> is a powerful static site generator that can be used to create various types of websites, including blogs. It is built with JavaScript and requires no prior knowledge of any particular web development framework. With Eleventy, you can create fast, simple, and efficient static sites without worrying about setting up a complicated development environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zG4LYKTf34ZWtIOtc1TcMw.png" /></figure><p>Getting started with Eleventy:</p><h4>Install Node.js and create folder for project</h4><p>Before you start using Eleventy, make sure that you have Node.js installed on your computer. You can download the latest version of Node.js from the official website and follow the instructions to install it.</p><p>Create a new directory on your computer where you want to store your blog files. You can name it whatever you want.</p><h4>Initialize your project</h4><p>Open your terminal and navigate to your new directory. Run the following command to initialize your project with npm:</p><pre>npm init -y</pre><p>This will create a package.json file in your directory.</p><h4>Install Eleventy</h4><p>Run the following command in your terminal to install Eleventy:</p><pre>npm install --save-dev @11ty/eleventy</pre><p>This will install Eleventy as a development dependency in your project.</p><h4>Create your first template</h4><p>Create a new file in your directory called index.html. This will be the homepage of your blog. Add some basic HTML to this file, like so:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>  &lt;head&gt;<br>    &lt;title&gt;My Blog&lt;/title&gt;<br>  &lt;/head&gt;<br>  &lt;body&gt;<br>    &lt;h1&gt;Welcome to my blog!&lt;/h1&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><h4>Create a configuration file</h4><p>Create a new file in your directory called .eleventy.js. This file will contain your configuration options for Eleventy. Add the following code to this file:</p><pre>module.exports = function(eleventyConfig) {<br>  eleventyConfig.addPassthroughCopy(&quot;assets&quot;);<br><br>  return {<br>    dir: {<br>      input: &quot;.&quot;,<br>      output: &quot;_site&quot;,<br>      includes: &quot;includes&quot;,<br>      layouts: &quot;layouts&quot;,<br>      data: &quot;data&quot;<br>    }<br>  };<br>};</pre><p>This code tells Eleventy to look for templates in the current directory, output the generated files to a directory called _site, and use the includes, layouts, and data directories to organize your templates.</p><h4>Build your site</h4><p>In your terminal, run the following command to build your site with Eleventy:</p><pre>npx eleventy</pre><p>This will generate your blog files in the _site directory.</p><h4>Preview your site</h4><p>To preview your blog, you can run a local web server in the _site directory. One way to do this is to use the http-server package. Run the following command to install it:</p><pre>npm install -g http-server</pre><p>Then, run the following command in your terminal to start the server:</p><pre>http-server _site</pre><p>This will start the server at http://localhost:8080. Open your web browser and navigate to this URL to see your blog!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8187b7547ff4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[VScode everywhere]]></title>
            <link>https://sebacode.medium.com/vscode-everywhere-3ccfcdbece71?source=rss-95507395cd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ccfcdbece71</guid>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[vscode-server]]></category>
            <dc:creator><![CDATA[Sebastián Vidal Aedo]]></dc:creator>
            <pubDate>Wed, 08 Feb 2023 13:08:37 GMT</pubDate>
            <atom:updated>2023-02-08T13:08:37.977Z</atom:updated>
            <content:encoded><![CDATA[<p>How to use full vscode from anywhere? the first answer would be <a href="https://vscode.dev/">https://vscode.dev/</a>, but it is not “complete”. The option to have a full vscode and access it from anywhere is to use <strong>vscode server</strong> (even from a tablet or cell phone).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rhr-Mt044ny35Baq_ufE0Q.png" /></figure><p><a href="https://coder.com/docs/code-server/latest">Home - code-server Docs</a></p><p>For this POC I will use an aws instance, where to install the vscode-server (I will assume that the EC2 instance already exists).</p><h4>Install vscode-sever</h4><p>Inside our instance we execute:</p><pre>wget https://github.com/cdr/code-server/releases/download/3.1.1/code-server-3.1.1-linux-x86_64.tar.gz<br>tar -xvzf code-server-3.1.1-linux-x86_64.tar.gz<br>sudo mv code-server-3.1.1-linux-x86_64 /opt/code-server<br>sudo ln -s /opt/code-server/code-server /usr/local/bin/code-server</pre><h4>Configure</h4><p>We edit the vscode-server configuration</p><pre>sudo nano /etc/code-server.conf</pre><p>leaving the following content</p><pre>#!/bin/sh<br> <br># Start code-server<br>/usr/local/bin/code-server - auth password - port 8080</pre><p>with this we tell it that we will use a password and that vscode-server will be exposed through port 8080.</p><h4>Start</h4><p>We can modify the “start” of the server, in order to indicate certain parameters (like the password). For this we edit the file <strong>code-server.service</strong> (before we give it execution permissions)</p><pre>sudo chmod +x /etc/code-server.conf<br>sudo nano /etc/systemd/system/code-server.service</pre><p>inside code-server.service we leave the following</p><pre>[Unit]<br>Description=CodeServer<br> <br>[service]<br>Environment=PASSWORD=yoour_custom_password_to_access_here<br>ExecStart=/etc/code-server.conf<br>restart=always<br>User=your_user<br> <br>[Install]<br>WantedBy=multi-user.target</pre><h4>Service</h4><p>We give execution permissions</p><pre>sudo chmod +x /etc/systemd/system/code-server.service</pre><p>Start and status</p><pre>sudo systemctl start code-server<br>sudo systemctl enable code-server<br>sudo systemctl status code-server</pre><h4>The Server: Nginx</h4><p>Install</p><pre>sudo apt install nginx</pre><p>Edit config file</p><pre>sudo nano /etc/nginx/sites-available/vscode-server</pre><p>Update content to:</p><pre>server { <br> listen 80; <br> server_name ip.number.your.ec2; <br> <br> location / { <br>   proxy_pass http://127.0.0.1:8080; <br>   proxy_http_version 1.1; <br>   proxy_set_header Upgrade $http_upgrade; <br>   proxy_set_header Connection &quot;upgrade&quot;; <br>   proxy_set_header Host $host; <br> } <br>}</pre><p>Enabled and restart nginx</p><pre>sudo ln -s /etc/nginx/sites-available/vscode-server /etc/nginx/sites-enabled/ <br>sudo systemctl restart nginx <br>sudo nginx -t</pre><p>Then, we access the ip of our EC two and we will see a login</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H6nbLtJZ76quh-uKy7FjsA.png" /></figure><p>With the password we set in <strong>code-server.service</strong> we can access and that’s all!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZOxK5wm1s_CMS8yvHGPT3w.png" /></figure><h4>Extra</h4><p>If you want to use extensions that use specific ports, for example LiveServer, you must open the port in your instance rules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b3NbDQin86tjeyxlZhOHZw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ccfcdbece71" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[BeEF!: take browser control]]></title>
            <link>https://sebacode.medium.com/beef-take-browser-control-bbd4c7eedf5b?source=rss-95507395cd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/bbd4c7eedf5b</guid>
            <category><![CDATA[browser-security]]></category>
            <category><![CDATA[safeweb]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[beef]]></category>
            <dc:creator><![CDATA[Sebastián Vidal Aedo]]></dc:creator>
            <pubDate>Sat, 24 Dec 2022 21:13:09 GMT</pubDate>
            <atom:updated>2022-12-24T21:13:09.833Z</atom:updated>
            <content:encoded><![CDATA[<p>This is why you should never click on an unknown link</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BqdP5blV_593FSAQRqwnQA.png" /></figure><p><strong>NEVER DO THIS</strong>, just for proof of concept or entertainment with friends. <strong>NEVER</strong>, I repeat, <strong>NEVER</strong>, because it is <strong>incorrect</strong> and also a crime.</p><h3>Ok, again, never do it, but what is a BeEF?</h3><p>Browser Exploitation Framework (<strong>BeEF</strong>), en pocas palabras, es apoderarse de la informacion del navegador mediante el acceso a una url.</p><p>El objetivo de este post es mostrar lo sencillo que podriamos ser hackeados medainte una url maliciosa (incluso cuenta un certificado seguro).</p><h4>Configuration</h4><p>We will use Linode, because give us a lot of tools to make this even easier.</p><p>Go to <a href="https://www.linode.com/">https://www.linode.com/</a> and create and account. Go to Linode and Create Linode (something like create instance on AWS).</p><p>Then:</p><ul><li>Go to Market. Search “BeEF” and select it.</li><li>Go down and setup BeEF assigning a Password (pass-beff-user) and an email for the encrypting, then the sudo user password.</li><li>The kind of Linode Plan, shared are cheaper.</li><li>Linode Label: the “name”.</li><li>Set a root password.</li></ul><p>Thats all (mandatory), of course we leave some fields as it was but you can experiment assigning some values.</p><p>We need to wait a few minutes to our “instance” or “linode” is <strong>Running</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ao5RPx9ZyDkvVVaXD88vMg.png" /></figure><p>When it finishes configuring and starts correctly, we connect through the terminal by accessing ssh (the info appears in our linode panel, in the upper right corner)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*__f1bW2Z6E5i4pYhEI_VxQ.png" /></figure><p>Inside the machine, we type</p><pre>cat /root/beef.info</pre><p>and we will see 2 things, one will be a message that everything went ok, something like</p><pre>##############################<br># BEEF INSTALLATION COMPLETE #<br>##############################</pre><p>and an endpoint-panel 😈 to access the BeEF Dashboard</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cBbmDTx5_PxcV205WhHvFA.png" /></figure><p>Here we use the username beef and the password we entered at the beginning (pass-beff-user). Inside, we see 2 urls in the first paragraph</p><ul><li>demo</li><li>advanced (this is the one we will use)</li></ul><h4>Go to hack ourselves</h4><p>Let’s copy the “advanced” link and open a dummy browser. Let’s go to the link! we will see something like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kkbtdb1LFCcNd4WQmBNCaA.png" /></figure><p>Nothing strange, BUT if we go back to the BeEF panel…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K1Vs9xXzn_fKqj6Ne9YA7A.png" /></figure><p>We did it!, but what can we do from now on? lots of things… as the <strong>goal of this is to learn how important it is not to click on an unknown link</strong> (and have fun).</p><p>Let’s go to <strong>Commands</strong> &gt; <strong>Browser</strong> &gt; <strong>Create Alert Dialog</strong>. We add a text and…. a pop-up appears in the browser hacked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RcZI9srECh8O-oBMNSultQ.png" /></figure><p><strong>Scary</strong>, but amazing (and very easy).</p><p>Now, something more creepy. Go to <strong>Social Engineering</strong> &gt; <strong>Google Phishing</strong> and <strong>execute</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xztjbrkftH4f7sMH8cZ_BA.png" /></figure><p>In the dummy-browser we will see…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xZeRVdBQ5MMGv_1jDdEZHw.png" /></figure><p>If wee add, for example the user and password, another page will open as an error, and the main page will show us the correcto google auth windows (as if we make a mistake). But, in BeEF panel Module Results History, we see in raw way the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*134mb4fzyVV_odowP3wHcg.png" /></figure><p>…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M0jc64pjjeOI0oP4oHVpgw.png" /></figure><p>Some things that would be interesting to be able to do? maybe see the Browsing History or capture the LocalStorage… but that for another time.</p><p>Remember <strong>never enter links you don’t know</strong>…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bbd4c7eedf5b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>