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.

190 lines
5.0 KiB

6 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. ## Legal
  11. **Unless otherwise stated**, everything in this repository can be
  12. assumed to fall under these two licenses depending on what type of file it is.
  13. #### Code, scripts
  14. All code, scripts, or other technical / programmatic items in this repo are
  15. assumed fall under the [Mozilla Public License 2.0](https://www.mozilla.org/en-US/MPL/)
  16. unless otherwise stated.
  17. #### Guides, articles, posts, misc. content
  18. ![Creative Commons Attribution-ShareAlike 4.0 International License](https://i.creativecommons.org/l/by-sa/4.0/88x31.png)
  19. All guides, scripts, posts, or otherwise non-programmatic content in this
  20. repo is assumed to fall under
  21. the [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/)
  22. unless otherwise stated.
  23. ## MYSQL Schema
  24. ![](blogSql.svg)
  25. ```SQL
  26. create database jrtechs_blog;
  27. use jrtechs_blog;
  28. create table users(
  29. user_id mediumint unsigned not null AUTO_INCREMENT,
  30. user_name varchar(60) not null,
  31. password char(64) not null,
  32. salt char(64) not null,
  33. primary key(user_id)
  34. );
  35. create table categories(
  36. category_id mediumint unsigned not null AUTO_INCREMENT,
  37. name varchar(60) not null,
  38. url varchar(60) not null,
  39. primary key(category_id)
  40. );
  41. create table posts(
  42. post_id mediumint unsigned not null AUTO_INCREMENT,
  43. category_id mediumint unsigned not null,
  44. picture_url varchar(100) not null,
  45. published datetime not null,
  46. name varchar(100) not null,
  47. url varchar(100) not null,
  48. primary key(post_id)
  49. );
  50. create table downloads(
  51. download_id mediumint unsigned not null AUTO_INCREMENT,
  52. file varchar(40) not null,
  53. name varchar(40) not null,
  54. download_count mediumint not null,
  55. primary key(download_id)
  56. );
  57. create table popular_posts(
  58. popular_post_id mediumint unsigned not null AUTO_INCREMENT,
  59. post_id mediumint unsigned not null,
  60. primary key(popular_post_id)
  61. );
  62. grant all on jrtechs_blog.* to blog_user@localhost identified by "password";
  63. ```
  64. ## Node Dependencies
  65. ```bash
  66. npm install express
  67. npm install express-session
  68. npm install mysql
  69. npm install sanitizer
  70. npm install promise
  71. npm install highlight
  72. npm install crypto
  73. npm install remarkable
  74. npm install markdown
  75. npm install highlight.js
  76. npm install compression
  77. npm install memory-cache --save
  78. ```
  79. ## Color scheme
  80. The color scheme has been changing a lot recently.
  81. [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)
  82. Blue:
  83. - Primary: #3B536B
  84. - Secondary: #00BEB2
  85. Purple:
  86. - Primary: #513E7D
  87. - Secondary: #D2C0FF
  88. 8767D1
  89. top blue: 3B536B
  90. Secondary Blue: 498FBE
  91. highlight blue: 18BC9C
  92. ## Image Optimization
  93. Stuff for automated image compression
  94. ```
  95. apt-get install jpegoptim
  96. apt-get install optipng
  97. ./optimizeImages.sh
  98. ```
  99. ## NGINX Configuration
  100. ```
  101. #jrtechs.net.conf
  102. server {
  103. listen 80;
  104. server_name www.jrtechs.net jrtechs.net;
  105. # redirect http requests to https
  106. return 301 https://jrtechs.net$request_uri;
  107. }
  108. server {
  109. listen 443 ssl http2;
  110. server_name jrtechs.net;
  111. ssl_certificate /etc/letsencrypt/live/jrtechs.net/cert.pem;
  112. ssl_certificate_key /etc/letsencrypt/live/jrtechs.net/privkey.pem;
  113. location / {
  114. proxy_pass http://localhost:8000;
  115. proxy_http_version 1.1;
  116. proxy_set_header Upgrade $http_upgrade;
  117. proxy_set_header Connection 'upgrade';
  118. proxy_set_header Host $host;
  119. proxy_cache_bypass $http_upgrade;
  120. }
  121. }
  122. #admin.jrtechs.net.con
  123. server {
  124. listen 80;
  125. server_name www.admin.jrtechs.net admin.jrtechs.net;
  126. # redirect http requests to https
  127. return 301 https://admin.jrtechs.net$request_uri;
  128. }
  129. server {
  130. listen 443 ssl http2;
  131. server_name admin.jrtechs.net;
  132. ssl_certificate /etc/letsencrypt/live/admin.jrtechs.net/cert.pem;
  133. ssl_certificate_key /etc/letsencrypt/live/admin.jrtechs.net/privkey.pem;
  134. location / {
  135. proxy_pass http://localhost:8001;
  136. proxy_http_version 1.1;
  137. proxy_set_header Upgrade $http_upgrade;
  138. proxy_set_header Connection 'upgrade';
  139. proxy_set_header Host $host;
  140. proxy_cache_bypass $http_upgrade;
  141. }
  142. }
  143. ```