Home / Companies / Strapi / Blog / January 2022

January 2022 Summaries

12 posts from Strapi

Filter
Month: Year:
Post Summaries Back to Blog
This is an interesting tutorial on building a URL Shortener Service using Next.js and Strapi. The project covers the creation of a backend API using Strapi to store and manage shortened URLs, as well as a frontend application built with Next.js that interacts with the backend API. The tutorial provides a detailed guide on how to set up the project, create routes for different pages, handle user authentication, and implement features such as registration, login, and URL shortening. The finished app allows users to register, log in, and access their shortened URLs, while also providing analytics on the number of visits to each alias. Overall, this tutorial demonstrates how easily it is possible to build a functional URL Shortener Service using popular web development frameworks and tools.
Jan 31, 2022 5,748 words in the original blog post.
The text provides a comprehensive guide on implementing database transactions in Strapi, a headless content management system built with React.js and Node.js. It illustrates the importance of using transactions to prevent partial data processing and ensure consistency, particularly in scenarios involving critical operations like financial transfers. The guide details how to integrate transactions using Knex.js and Bookshelf.js libraries, which Strapi relies on for database interactions, covering both theoretical concepts and practical application through code examples. The document also highlights the significance of transactions in preventing race conditions and maintaining data integrity, demonstrating the potential pitfalls of handling multiple database queries without transactional support. It explains how transactions ensure that queries are isolated, preventing interference and maintaining stability even during concurrent operations, and discusses the role of isolation levels in balancing performance and data safety.
Jan 26, 2022 2,302 words in the original blog post.
The tutorial provides a comprehensive guide to building an E-commerce store using a Nuxt.js frontend and a Strapi backend, along with integrations of Nodemailer for email notifications and Stripe for payment processing. It begins with setting up the Strapi headless CMS, which facilitates rapid API development and customization, followed by the installation and configuration of Nuxt.js in server-side rendering mode with Tailwind CSS for styling. The tutorial details the creation of various components and pages for the store, such as Hero, Ads, Footer, and Products sections, and demonstrates using Vuex for state management. It also covers setting up a newsletter subscription feature with @nuxtjs/strapi for backend API calls and the use of @nuxtjs/swal for user alerts. Additionally, the guide explains integrating Stripe for secure payment processing, including setting up Stripe sessions and handling checkout processes, and concludes with implementing Nodemailer in Strapi to send welcome emails to subscribers.
Jan 25, 2022 4,805 words in the original blog post.
In this tutorial, we will be building an E-Commerce store using Strapi as our backend framework. We will also use Nuxt.js for the frontend and Stripe for payment processing. Additionally, we will set up a simple email service to notify subscribers when they sign up. Firstly, you need to install Node.js and npm (Node Package Manager) on your computer if you haven't already done so. You can download them from the official website: https://nodejs.org/en/download/. Next, create a new project folder for our E-Commerce store and navigate into it using the terminal or command prompt. Then run the following commands to initialize a new Node.js project: ```bash npm init -y ``` This will generate a package.json file in your project directory. Now, let's install Strapi and other necessary dependencies by running the following command: ```bash npm install strapi @strapi/generator-admin@latest @strapi/generator-content-type@latest nodemon --save-dev ``` After installation is complete, create a new Strapi project within your current directory using the following command: ```bash npx create-strapi-app ./api --quickstart ``` This will prompt you to enter some details about your application. Fill in the required fields and wait for the installation process to finish. Once it's done, start your Strapi server by running: ```bash npm run develop ``` Now that our backend is set up, let's move on to installing Nuxt.js as our frontend framework. Run the following command in your terminal or command prompt: ```bash npx create-nuxt-app nuxt-strapi-ecommerce ``` Fill in the prompts with appropriate details and wait for the installation process to finish. Once it's done, navigate into your newly created Nuxt.js project folder using the terminal or command prompt: ```bash cd nuxt-strapi-ecommerce ``` Now let's install Stripe by running the following command: ```bash npm install stripe --save ``` To get started with Stripe, go to https://stripe.com/ and register to obtain your API keys before proceeding with this tutorial. Once you've done that, I'll assume you've gotten your API keys and you're ready to proceed. Installing Stripe Package Execute the following code to install Stripe: ```bash yarn add stripe # using yarn npm install stripe # using npm ``` Look for the .env.example file in the root folder of your Strapi application and rename it to .env. Then add the following line of text to it: ```bash STRIPE_KEY=<YOUR_STRIPE_KEY> ``` Replace <YOUR_STRIPE_KEY> with your Stripe credentials. Then proceed as follows to open up the order.js controller: ```bash cd src/api cd order cd controllers code order.js # open in your editor ``` Edit the contents of order.js to look like: ```javascript 'use strict'; const stripe = require('stripe')(process.env.STRIPE_KEY) const MY_DOMAIN = 'http://localhost:3000/cart'; const { createCoreController } = require('@strapi/strapi').factories; module.exports = createCoreController('api::order.order', ({ strapi }) => ({ async create(ctx) { const { cartDetail, cartTotal } = ctx.request.body // build line items array const line_items = cartDetail.map((cartItem) => { const item = {} item.price_data = { currency: 'usd', product_data: { name: cartItem.name, images: [`${cartItem.url}`] }, unit_amount: (cartItem.price * 100).toFixed(0), }, item.quantity = cartItem.quantity return item; }) // create order await strapi.service('api::order.order').create({ data: { item: line_items}}); const session = await stripe.checkout.sessions.create({ payment_method_types: ['card'], line_items, mode: 'payment', success_url: `${MY_DOMAIN}?success=true`, cancel_url: `${MY_DOMAIN}?canceled=true`, }) return { id: session.id} } })); ``` What we've done here is to redefine the create endpoint. Now when we hit the /order/create endpoint, we generate a line_items array which is stored in our database and also sent to Stripe as product details along with other essential details related to purchases. Finally, we return a JSON object containing an id with the Stripe session ID. That's all for Stripe on the backend. Next, open your Nuxt.js application to add Stripe support on the frontend. Installing @stripe/stripe-js To start using Stripe in our Nuxt.js application, we have to install a package to help us make the process easier. Execute the following code to install @stripe/stripe-js: ```bash yarn add @stripe/stripe-js # using yarn npm install @stripe/stripe-js # using npm ``` Open up your cart.vue file, then add the following lines of code to it: ```javascript export default { data() { return { dataItems: {}, session: {}, stripe: {}, stripePromise: {}, } }, computed: { ...mapGetters(['getCart', 'getCartTotal']), }, mounted() { this.displayMessage() }, methods: { async handleSubmit(e) { e.preventDefault() const response = await this.$http.$post( `http://localhost:1337/api/orders`, { cartDetail: this.getCart, cartTotal: this.getCartTotal.toFixed(2), } ) this.$swal({ title: 'Please wait', text: 'redirecting you to stripe, click ok', icon: 'success', button: 'Ok', }) // stripe logic const stripePromise = loadStripe(process.env.STRIPE_KEY) const session = response const stripe = await stripePromise const result = await stripe.redirectToCheckout({ sessionId: session.id, }) console.log(response) if (result.error) { this.$nuxt.context.error(result.error.message) } }, // using vue-swal to display messages displayMessage() { if (this.$route.query.success) { this.$swal({ title: 'Order placed!', text: 'Thanks for placing your orders', icon: 'success', button: 'Ok', }) } else if (this.$route.query.canceled) { this.$swal({ title: 'Order canceled!', text: "continue to shop around and checkout when you're ready.", icon: 'warning', button: 'Ok', }) } }, formatCartTotal(num) { if (num > 0) { return num.toFixed(2) } else { return num } }, ...mapActions(['deleteCartItem']), }, } ``` Replace <YOUR_STRIPE_KEY> with your Stripe credentials. Now, we should have Stripe working across the whole application. To install Nodemailer, run: ```bash yarn add nodemailer # using yarn npm install nodemailer # using npm ``` Open up your Strapi application and execute the following code to access the subscriber.js controller: ```bash cd src/api cd subscriber cd controllers code subscriber.js ``` Add the following lines of code to your subscriber.js file: ```javascript 'use strict'; const nodemailer = require('nodemailer') module.exports = { async create(ctx) { const { Email } = ctx.request.body const existingSub = await strapi.services.subscriber.find({ Email }) if (!existingSub) { await strapi.services.subscriber.create({ Email }) try { let transporter = nodemailer.createTransport({ service: "gmail", auth: { user: <your_email>, pass: <your_password>, } }) const mailOptions = { from: 'Unique essense stores', to: `${Email}`, subject: 'Welcome', text: `Hey @${Email}, Thanks for subscribing to our NewsLetter` }; await transporter.sendMail(mailOptions) } catch (error) { console.log(error) } } return Email } }; ``` In the code above, using Nodemailer, we've set up an email service that sends out notifications to subscribers. In order for Nodemailer to work with Gmail, you need to turn on less secure app access. You can do so here: https://www.google.com/settings/security/lesssecureapps Well devs, that's all for now. I hope this tutorial has given you an insight into how to build your own E-Commerce store with Strapi. You could even add more features to your store if you like.
Jan 25, 2022 4,807 words in the original blog post.
The tutorial outlines a step-by-step process for integrating Cloudinary as a default upload provider in a Strapi application, emphasizing its utility for managing images and videos. Beginning with instructions on setting up a Cloudinary account, the guide details configuring Strapi to connect with Cloudinary, including setting necessary environment variables and permissions. It then transitions to building a front-end application using Next.js, employing Apollo Client for GraphQL interactions to display data stored in Strapi. The tutorial also highlights the benefits of Next.js's Image component for optimized image rendering and concludes with a discussion on hosting options, introducing Strapi Cloud as a solution for managing infrastructure while maintaining Strapi’s open-source flexibility. Throughout, the tutorial underscores the ease of switching providers and customizability within the Strapi ecosystem.
Jan 24, 2022 2,565 words in the original blog post.
The tutorial outlines the process of building a corporate design agency website using Strapi as a headless CMS for managing content and NuxtJS for the front-end. It begins by explaining the benefits of using a headless CMS, such as the flexibility to choose any front-end technology, unlike traditional monolithic CMSs like WordPress or Drupal. The guide details how to set up Strapi, create content types for articles, projects, and user-submitted content, and configure roles and permissions to allow data access. On the front end, NuxtJS is used with TailwindCSS for styling, displaying content fetched from Strapi via APIs, and managing dynamic pages. The tutorial also covers sending data to Strapi using forms on the website, demonstrating the integration of back-end content management with a modern front-end framework. The complete source code for the project is available on GitHub for reference and further exploration.
Jan 19, 2022 5,794 words in the original blog post.
StrapiConf 2022, the second global user conference for Strapi, is set to take place on March 16 and 17, with a newly launched website offering registration that includes a special "Strapi Fragment" with each ticket. Attendees can generate their conference tickets using their GitHub accounts, although registration is confirmed without one. The event will feature a hackathon focused on creating plugins to enhance the Strapi ecosystem, with winners having the opportunity to present their creations at the conference. The conference has attracted sponsors such as Gatsby, Medusa Commerce, and Netlify, and is open to additional sponsorships. Additionally, the call for papers is open, with an extended submission deadline approaching, inviting speakers to contribute to the theme of "building faster, together." Attendees can stay updated on the schedule and speaker announcements by following @strapijs on social media.
Jan 18, 2022 321 words in the original blog post.
The tutorial provides a comprehensive guide to creating a podcast app using Strapi and Nuxt.js, highlighting the integration of these tools to manage and display audio content. Strapi, a headless CMS, allows users to build and manage APIs with an open-source and self-hosted approach, while Nuxt.js serves as a framework for developing universal Vue.js applications that support both client-side and server-side rendering. The tutorial covers the step-by-step setup of Strapi to create a podcast collection type, configure permissions, and test API endpoints using Postman. It then transitions to building a Nuxt.js frontend, detailing the installation of necessary modules and configuration files to fetch and display podcast data from Strapi. Through practical coding examples, the tutorial demonstrates how to create a dynamic podcasts page and individual podcast pages, allowing users to listen to audio directly on the app. The guide concludes by encouraging users to explore further customization options with Strapi and provides a GitHub repository for accessing the complete source code.
Jan 17, 2022 1,832 words in the original blog post.
Strapi, a JavaScript-based headless CMS, offers a flexible and efficient alternative to traditional CMS platforms like WordPress by decoupling content from presentation, enabling developers to utilize various technologies for frontend development while maintaining a familiar interface for content creators. The guide illustrates how to set up a CSS-Tricks clone using Strapi for the backend and Next.js for the frontend, providing detailed instructions on creating and managing content types such as articles, authors, and tags. This approach enhances security by limiting direct access between the content platform and the database, reduces the risk of DDoS attacks, and allows content to be easily repurposed across multiple channels. The tutorial emphasizes the ease of starting a Strapi project, setting up a content model, and creating a scalable frontend application by using Next.js, showcasing the use of API endpoints to fetch and display content dynamically. Additionally, the tutorial provides styling tips to mimic the CSS-Tricks design, demonstrating how Strapi and Next.js offer a robust and versatile solution for building modern content-driven websites.
Jan 12, 2022 1,867 words in the original blog post.
A headless CMS, such as Strapi, is an excellent option for organizations that want to create an omnichannel digital system, allowing content to be displayed smoothly on various devices. It's a flexible solution that reduces development time and effort. The market value of the headless CMS market was $328.5 million in 2019 and is projected to reach $1,628.6 million by 2027 with a growth rate of 22.6%. This type of CMS consists of a database and content delivery using an API, separating the back-end and front-end. It's ideal for companies that need to adapt to new devices and platforms, such as online stores or those planning to use Internet of Things capabilities. In contrast, no-code website builders, like Squarespace or Webflow, offer templates and blocks that allow users to create a website without coding skills. They are great for simple projects, but may not be suitable for complex, ambitious projects. When choosing between a headless CMS and a no-code tool, it's essential to consider the needs of your team and the features of your product.
Jan 10, 2022 1,928 words in the original blog post.
Strapi is a headless CMS that provides backend infrastructure for applications, allowing developers to choose any frontend technology, such as Next.js, to consume the APIs—REST or GraphQL—it creates from the stored data. This guide details the process of implementing authenticated requests to Strapi using Next.js, ensuring that only authenticated users can access certain endpoints. The tutorial includes setting up a new Strapi application and a Next.js frontend, creating user roles and permissions within Strapi to restrict public access, and fetching data from Strapi's API. It also covers using JSON Web Tokens (JWT) for authentication and storing these tokens in cookies to streamline future requests. By following these steps, developers can secure their backend while providing a seamless experience for authenticated users, with further suggestions to build complete login and logout functionalities for enhanced security.
Jan 06, 2022 2,205 words in the original blog post.
Strapi, a headless content management system (CMS), offers significant flexibility for creating SEO-friendly websites by allowing users to choose their preferred front-end frameworks such as Remix, Next.js, or Gatsby. This CMS excels in SEO optimization when used with the Jamstack model, which leverages JavaScript, APIs, and Markup to enhance web development and user experience. Strapi enables the generation of clean URLs using slugs, the addition of metadata through components, and the implementation of structured data for better search engine visibility. Moreover, Strapi's community-contributed sitemap plugin automatically generates and updates sitemaps, ensuring accurate site representation in search engines. By maintaining a well-organized content structure and integrating various SEO practices, Strapi positions itself as an effective tool for developers seeking control over their data while embracing the Jamstack movement.
Jan 04, 2022 2,301 words in the original blog post.