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.

203 lines
5.5 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. ![](docs/blogSql.svg)
  25. ```mysql
  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. create table traffic_log(
  63. log_id mediumint unsigned not null AUTO_INCREMENT,
  64. url varchar(60) not null,
  65. ip varchar(20) not null,
  66. date datetime not null,
  67. primary key(log_id)
  68. );
  69. grant all on jrtechs_blog.* to blog_user@localhost identified by "password";
  70. ```
  71. ## Node Dependencies
  72. ```bash
  73. npm install express
  74. npm install express-session
  75. npm install mysql
  76. npm install sanitizer
  77. npm install promise
  78. npm install highlight
  79. npm install crypto
  80. npm install remarkable
  81. npm install markdown
  82. npm install highlight.js
  83. npm install compression
  84. npm install memory-cache --save
  85. npm install request
  86. npm install nodemailer
  87. npm install nodemailer-smtp-transport
  88. npm install node-pandoc
  89. ```
  90. ## Color scheme
  91. The color scheme has been changing a lot recently.
  92. [Adobe Color Wheel](https://color.adobe.com/create/color-wheel/?copy=true&base=2&rule=Custom&selected=4&name=Copy%20of%20Site&mode=cmyk&rgbvalues=0.17254901960784313,0.24313725490196078,0.3137254901960784,0.28627450980392155,0.5607843137254902,0.7450980392156863,0.5329137283008958,0.7301501780381741,1,0.8235294117647058,0.7529411764705882,1,0.042420144797897574,0,0.17000000000000004&swatchOrder=0,1,2,3,4)
  93. current:
  94. top 2C3E50
  95. secondary 498FBE
  96. highlight:00F0E1, 88BAFF
  97. ## Image Optimization
  98. Stuff for automated image compression
  99. ```
  100. apt-get install jpegoptim
  101. apt-get install optipng
  102. ./optimizeImages.sh
  103. ```
  104. ## NGINX Configuration
  105. ```
  106. #jrtechs.net.conf
  107. server {
  108. listen 80;
  109. server_name www.jrtechs.net jrtechs.net;
  110. # redirect http requests to https
  111. return 301 https://jrtechs.net$request_uri;
  112. }
  113. server {
  114. listen 443 ssl http2;
  115. server_name jrtechs.net;
  116. ssl_certificate /etc/letsencrypt/live/jrtechs.net/cert.pem;
  117. ssl_certificate_key /etc/letsencrypt/live/jrtechs.net/privkey.pem;
  118. location / {
  119. proxy_pass http://localhost:8000;
  120. proxy_http_version 1.1;
  121. proxy_set_header Upgrade $http_upgrade;
  122. proxy_set_header Connection 'upgrade';
  123. proxy_set_header Host $host;
  124. proxy_cache_bypass $http_upgrade;
  125. }
  126. }
  127. ```
  128. ```
  129. #admin.jrtechs.net.conf
  130. server {
  131. listen 80;
  132. server_name www.admin.jrtechs.net admin.jrtechs.net;
  133. # redirect http requests to https
  134. return 301 https://admin.jrtechs.net$request_uri;
  135. }
  136. server {
  137. listen 443 ssl http2;
  138. server_name admin.jrtechs.net;
  139. ssl_certificate /etc/letsencrypt/live/admin.jrtechs.net/cert.pem;
  140. ssl_certificate_key /etc/letsencrypt/live/admin.jrtechs.net/privkey.pem;
  141. location / {
  142. proxy_pass http://localhost:8001;
  143. proxy_http_version 1.1;
  144. proxy_set_header Upgrade $http_upgrade;
  145. proxy_set_header Connection 'upgrade';
  146. proxy_set_header Host $host;
  147. proxy_cache_bypass $http_upgrade;
  148. }
  149. }
  150. ```
  151. ## Projects Sites
  152. As I develop more projects I would like an easy way to add and host them on my website without having to create another subdomain and generate more ssl certs. I simply want the project site to be accessible under https://jrtechs.net/project_name.
  153. ### State Diagrm of Plan
  154. ![diagram](docs/projectsSites.svg)