Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Achmad Fatoni achmadfatoni

🏠
Working from home
View GitHub Profile
@achmadfatoni
achmadfatoni / node_nginx_ssl.md
Created Jul 30, 2020 — forked from bradtraversy/node_nginx_ssl.md
Node app deploy with nginx & SSL
View node_nginx_ssl.md

Node.js Deployment

Steps to deploy a Node.js app to DigitalOcean using PM2, NGINX as a reverse proxy and an SSL from LetsEncrypt

1. Sign up for Digital Ocean

If you use the referal link below, you get $10 free (1 or 2 months) https://m.do.co/c/5424d440c63a

2. Create a droplet and log in via ssh

I will be using the root user, but would suggest creating a new user

View generate_ssh_key
ssh-keygen -t rsa -b 4096 -C "achmadfatoni(replace with name)"
View fisher-yates-shuffle.php
<?php
/**
* It's an algorithm for generating a random permutation of a finit sequence - in plain terms, the algorithm shuffles the sequence.
*
* Reference: https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
*/
function MyShuffle(&$arr) {
@achmadfatoni
achmadfatoni / ssl_nginx.conf
Last active Dec 26, 2017
letsencrypt laravel configuration
View ssl_nginx.conf
## http://domain.com and http://www.domain.com redirect to https://www.domain.com
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name domain.com www.domain.com;
include /etc/nginx/snippets/letsencrypt.conf;
location / {
return 301 https://www.domain.com$request_uri;
View guzzle_raw_post_request.php
$client = new Client();
$array = [];
$res = $client->request('POST', $url, [
'body' => json_encode($array),
'headers' => [
'Content-Type' => 'application/json',
]
]);
View delete_post
public function delete($id)
{
$post = Post::find($id);
if ($post) {
$post->delete();
return response()->json([
'message' => 'Post has been deleted'
]);
View simple_api_lumen_model
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
protected $table = 'posts';
@achmadfatoni
achmadfatoni / simple_api_lumen_update_controller
Created Aug 18, 2017
simple_api_lumen_update_controller
View simple_api_lumen_update_controller
public function update(Request $request, $id)
{
$post = Post::find($id);
if ($post) {
$post->update($request->all());
return response()->json([
'message' => 'Post has been updated'
]);
@achmadfatoni
achmadfatoni / simple_api_lumen_single_controller
Created Aug 18, 2017
simple_api_lumen_single_controller
View simple_api_lumen_single_controller
public function show($id)
{
$post = Post::find($id);
if (! $post) {
return response()->json([
'message' => 'post not found'
]);
}
return $post;
View simple_api_lumen_delete_route
$app->delete('/posts/{id}', 'PostController@delete');
You can’t perform that action at this time.