Skip to content

Instantly share code, notes, and snippets.

View HabeebCycle's full-sized avatar

Habeeb Okunade HabeebCycle

View GitHub Profile
@HabeebCycle
HabeebCycle / mern-server-setup.md
Last active November 26, 2022 12:27 — forked from bradtraversy/mern-server-setup.md
Setup Ubuntu & Deploy MERN app

Linux Server Setup & MERN App Deployment

These are the steps to setup an Ubuntu server from scratch and deploy a MERN app with the PM2 process manager and Nginx. We are using Linode, but you could just as well use a different cloud provider or your own machine or VM.

https://www.youtube.com/watch?v=7aRjGIhwyQM

Create an account at Linode

Click on Create Linode

Choose your server options (OS, region, etc)

package com.habeebcycle.demo.api;
import com.habeebcycle.demo.api.model.User;
import com.habeebcycle.demo.api.service.UserService;
import org.junit.jupiter.api.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.test.web.reactive.server.WebTestClient;
package com.habeebcycle.demo.api.persistence;
import com.habeebcycle.demo.api.model.User;
import com.habeebcycle.demo.api.persistence.UserRepoImpl;
import com.habeebcycle.demo.api.repository.UserRepository;
import org.junit.jupiter.api.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.data.redis.DataRedisTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.dao.DuplicateKeyException;
package com.habeebcycle.demo.api.service;
import com.habeebcycle.demo.api.persistence.UserRepoImpl;
import com.habeebcycle.demo.api.model.User;
import com.habeebcycle.demo.api.repository.UserRepository;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@Service
package com.habeebcycle.demo.api.controller;
import com.habeebcycle.demo.api.model.User;
import com.habeebcycle.demo.api.service.UserService;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@RestController
@RequestMapping("/user")
package com.habeebcycle.demo.api.persistence;
import com.habeebcycle.demo.api.model.User;
import com.habeebcycle.demo.api.repository.UserRepository;
import org.reactivestreams.Publisher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.dao.OptimisticLockingFailureException;
import org.springframework.data.redis.core.ReactiveHashOperations;
import org.springframework.data.redis.core.ReactiveRedisOperations;
package com.habeebcycle.demo.api.repository;
import com.habeebcycle.demo.api.model.User;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import reactor.core.publisher.Mono;
public interface UserRepository extends ReactiveCrudRepository<User, String> {
Mono<User> findByUsername(String username);
Mono<User> findByEmail(String name);
Mono<Boolean> existsByUsername(String username);
package com.habeebcycle.demo.api.config;
import com.habeebcycle.demo.api.model.User;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.ReactiveRedisOperations;
import org.springframework.data.redis.core.ReactiveRedisTemplate;
@HabeebCycle
HabeebCycle / User.java
Last active January 22, 2021 05:34
User entity object
package com.habeebcycle.demo.api.model;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Version;
import java.io.Serializable;
public class User implements Serializable {
@Id
@HabeebCycle
HabeebCycle / pom.xml
Last active January 22, 2021 03:02
Reactive Api with Reactive Redis
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>