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.

189 lines
5.1 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. ```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. ```
  86. ## Color scheme
  87. The color scheme has been changing a lot recently.
  88. [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)
  89. current:
  90. top 2C3E50
  91. secondary 498FBE
  92. highlight:00F0E1, 88BAFF
  93. ## Image Optimization
  94. Stuff for automated image compression
  95. ```
  96. apt-get install jpegoptim
  97. apt-get install optipng
  98. ./optimizeImages.sh
  99. ```
  100. ## NGINX Configuration
  101. ```
  102. #jrtechs.net.conf
  103. server {
  104. listen 80;
  105. server_name www.jrtechs.net jrtechs.net;
  106. # redirect http requests to https
  107. return 301 https://jrtechs.net$request_uri;
  108. }
  109. server {
  110. listen 443 ssl http2;
  111. server_name jrtechs.net;
  112. ssl_certificate /etc/letsencrypt/live/jrtechs.net/cert.pem;
  113. ssl_certificate_key /etc/letsencrypt/live/jrtechs.net/privkey.pem;
  114. location / {
  115. proxy_pass http://localhost:8000;
  116. proxy_http_version 1.1;
  117. proxy_set_header Upgrade $http_upgrade;
  118. proxy_set_header Connection 'upgrade';
  119. proxy_set_header Host $host;
  120. proxy_cache_bypass $http_upgrade;
  121. }
  122. }
  123. #admin.jrtechs.net.con
  124. server {
  125. listen 80;
  126. server_name www.admin.jrtechs.net admin.jrtechs.net;
  127. # redirect http requests to https
  128. return 301 https://admin.jrtechs.net$request_uri;
  129. }
  130. server {
  131. listen 443 ssl http2;
  132. server_name admin.jrtechs.net;
  133. ssl_certificate /etc/letsencrypt/live/admin.jrtechs.net/cert.pem;
  134. ssl_certificate_key /etc/letsencrypt/live/admin.jrtechs.net/privkey.pem;
  135. location / {
  136. proxy_pass http://localhost:8001;
  137. proxy_http_version 1.1;
  138. proxy_set_header Upgrade $http_upgrade;
  139. proxy_set_header Connection 'upgrade';
  140. proxy_set_header Host $host;
  141. proxy_cache_bypass $http_upgrade;
  142. }
  143. }
  144. ```