Personal blog written from scratch using Node.js, Bootstrap, and MySQL. https://jrtechs.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
4.1 KiB

7 years ago
6 years ago
  1. # NodeJSBlog
  2. This is a project I did to recreate my word press blog using plane node js. If I were to
  3. do this again, I would use PHP. NodeJS is great, however, it was a pain to deal
  4. with all the asynchronous calls when trying to create a web page in a linear fashion.
  5. If you want to run this project, it requires Mysql, npm, and node to be installed. For
  6. deployment I used a [Nginx](https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04)
  7. proxy to expose the node application running on port 8000 to port 80. This proxy is necessary
  8. because you can't run a node application as port 80 unless you are root, which would be a
  9. security vulnerability.
  10. ## MYSQL Information
  11. ![](blogSql.svg)
  12. ```SQL
  13. create database jrtechs_blog;
  14. use jrtechs_blog;
  15. create table users(
  16. user_id mediumint unsigned not null AUTO_INCREMENT,
  17. user_name varchar(60) not null,
  18. password char(64) not null,
  19. salt char(64) not null,
  20. primary key(user_id)
  21. );
  22. create table categories(
  23. category_id mediumint unsigned not null AUTO_INCREMENT,
  24. name varchar(60) not null,
  25. url varchar(60) not null,
  26. primary key(category_id)
  27. );
  28. create table posts(
  29. post_id mediumint unsigned not null AUTO_INCREMENT,
  30. category_id mediumint unsigned not null,
  31. picture_url varchar(100) not null,
  32. published datetime not null,
  33. name varchar(100) not null,
  34. url varchar(100) not null,
  35. primary key(post_id)
  36. );
  37. create table downloads(
  38. download_id mediumint unsigned not null AUTO_INCREMENT,
  39. file varchar(40) not null,
  40. name varchar(40) not null,
  41. download_count mediumint not null,
  42. primary key(download_id)
  43. );
  44. create table popular_posts(
  45. popular_post_id mediumint unsigned not null AUTO_INCREMENT,
  46. post_id mediumint unsigned not null,
  47. primary key(popular_post_id)
  48. );
  49. grant all on jrtechs_blog.* to blog_user@localhost identified by "password";
  50. ```
  51. ## Node Dependencies
  52. ```bash
  53. npm install express
  54. npm install express-session
  55. npm install mysql
  56. npm install sanitizer
  57. npm install promise
  58. npm install highlight
  59. npm install crypto
  60. npm install remarkable
  61. npm install markdown
  62. npm install highlight.js
  63. npm install compression
  64. npm install memory-cache --save
  65. ```
  66. ## Color scheme
  67. [Adobe Color Wheel](https://color.adobe.com/create/color-wheel/?copy=true&base=2&rule=Custom&selected=3&name=Copy%20of%20Site&mode=rgb&rgbvalues=0.231,0.325499999999957,0.42,0,0.7450980392156863,0.6980392156862745,0.10196078431372549,0.36470588235294116,0.38823529411764707,0.8235294117647058,0.7529411764705882,1,0.3165071770335184,0.24148325358851674,0.49&swatchOrder=0,1,2,3,4)
  68. Blue:
  69. - Primary: #3B536B
  70. - Secondary: #00BEB2
  71. Purple:
  72. - Primary: #513E7D
  73. - Secondary: #D2C0FF
  74. 8767D1
  75. top blue: 3B536B
  76. Secondary Blue: 498FBE
  77. highlight blue: 18BC9C
  78. Stuff for automated image compression
  79. ```
  80. apt-get install jpegoptim
  81. jpegoptim --size=500k *.jpg
  82. apt-get install optipng
  83. optipng *.png
  84. ```
  85. ```
  86. server {
  87. listen 80;
  88. server_name www.jrtechs.net jrtechs.net;
  89. # redirect http requests to https
  90. return 301 https://jrtechs.net$request_uri;
  91. }
  92. server {
  93. listen 443 ssl http2;
  94. server_name jrtechs.net;
  95. ssl_certificate /etc/letsencrypt/live/jrtechs.net/cert.pem;
  96. ssl_certificate_key /etc/letsencrypt/live/jrtechs.net/privkey.pem;
  97. location / {
  98. proxy_pass http://localhost:8000;
  99. proxy_http_version 1.1;
  100. proxy_set_header Upgrade $http_upgrade;
  101. proxy_set_header Connection 'upgrade';
  102. proxy_set_header Host $host;
  103. proxy_cache_bypass $http_upgrade;
  104. }
  105. }
  106. server {
  107. listen 80;
  108. server_name www.admin.jrtechs.net admin.jrtechs.net;
  109. # redirect http requests to https
  110. return 301 https://admin.jrtechs.net$request_uri;
  111. }
  112. server {
  113. listen 443 ssl http2;
  114. server_name admin.jrtechs.net;
  115. ssl_certificate /etc/letsencrypt/live/admin.jrtechs.net/cert.pem;
  116. ssl_certificate_key /etc/letsencrypt/live/admin.jrtechs.net/privkey.pem;
  117. location / {
  118. proxy_pass http://localhost:8001;
  119. proxy_http_version 1.1;
  120. proxy_set_header Upgrade $http_upgrade;
  121. proxy_set_header Connection 'upgrade';
  122. proxy_set_header Host $host;
  123. proxy_cache_bypass $http_upgrade;
  124. }
  125. }
  126. ```