├── .angulardoc.json ├── .gitignore ├── LICENSE ├── README.md ├── app.js ├── bin └── www ├── client ├── .angulardoc.json ├── .editorconfig ├── .gitignore ├── angular.json ├── browserslist ├── e2e │ ├── protractor.conf.js │ ├── src │ │ ├── app.e2e-spec.ts │ │ └── app.po.ts │ └── tsconfig.json ├── karma.conf.js ├── package-lock.json ├── package.json ├── src │ ├── app │ │ ├── admin │ │ │ ├── admin.component.html │ │ │ ├── admin.component.scss │ │ │ ├── admin.component.spec.ts │ │ │ └── admin.component.ts │ │ ├── app-routing.module.ts │ │ ├── app.component.html │ │ ├── app.component.scss │ │ ├── app.component.spec.ts │ │ ├── app.component.ts │ │ ├── app.module.ts │ │ ├── auth.service.spec.ts │ │ ├── auth.service.ts │ │ ├── auth │ │ │ ├── auth.guard.spec.ts │ │ │ ├── auth.guard.ts │ │ │ ├── login │ │ │ │ ├── login.component.html │ │ │ │ ├── login.component.scss │ │ │ │ ├── login.component.spec.ts │ │ │ │ └── login.component.ts │ │ │ └── register │ │ │ │ ├── register.component.html │ │ │ │ ├── register.component.scss │ │ │ │ ├── register.component.spec.ts │ │ │ │ └── register.component.ts │ │ ├── bycategory │ │ │ ├── bycategory.component.html │ │ │ ├── bycategory.component.scss │ │ │ ├── bycategory.component.spec.ts │ │ │ └── bycategory.component.ts │ │ ├── category.service.spec.ts │ │ ├── category.service.ts │ │ ├── category │ │ │ ├── category-add │ │ │ │ ├── category-add.component.html │ │ │ │ ├── category-add.component.scss │ │ │ │ ├── category-add.component.spec.ts │ │ │ │ └── category-add.component.ts │ │ │ ├── category-details │ │ │ │ ├── category-details.component.html │ │ │ │ ├── category-details.component.scss │ │ │ │ ├── category-details.component.spec.ts │ │ │ │ └── category-details.component.ts │ │ │ ├── category-edit │ │ │ │ ├── category-edit.component.html │ │ │ │ ├── category-edit.component.scss │ │ │ │ ├── category-edit.component.spec.ts │ │ │ │ └── category-edit.component.ts │ │ │ ├── category.component.html │ │ │ ├── category.component.scss │ │ │ ├── category.component.spec.ts │ │ │ ├── category.component.ts │ │ │ └── category.ts │ │ ├── details │ │ │ ├── details.component.html │ │ │ ├── details.component.scss │ │ │ ├── details.component.spec.ts │ │ │ └── details.component.ts │ │ ├── home.service.spec.ts │ │ ├── home.service.ts │ │ ├── home │ │ │ ├── home.component.html │ │ │ ├── home.component.scss │ │ │ ├── home.component.spec.ts │ │ │ └── home.component.ts │ │ ├── interceptors │ │ │ └── token.interceptor.ts │ │ ├── post.service.spec.ts │ │ ├── post.service.ts │ │ └── post │ │ │ ├── post-add │ │ │ ├── post-add.component.html │ │ │ ├── post-add.component.scss │ │ │ ├── post-add.component.spec.ts │ │ │ └── post-add.component.ts │ │ │ ├── post-details │ │ │ ├── post-details.component.html │ │ │ ├── post-details.component.scss │ │ │ ├── post-details.component.spec.ts │ │ │ └── post-details.component.ts │ │ │ ├── post-edit │ │ │ ├── post-edit.component.html │ │ │ ├── post-edit.component.scss │ │ │ ├── post-edit.component.spec.ts │ │ │ └── post-edit.component.ts │ │ │ ├── post.component.html │ │ │ ├── post.component.scss │ │ │ ├── post.component.spec.ts │ │ │ ├── post.component.ts │ │ │ └── post.ts │ ├── assets │ │ └── .gitkeep │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── main.ts │ ├── polyfills.ts │ ├── styles.scss │ └── test.ts ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.spec.json └── tslint.json ├── config ├── passport.js └── settings.js ├── models ├── Category.js ├── Post.js └── User.js ├── package-lock.json ├── package.json ├── public ├── index.html └── stylesheets │ └── style.css └── routes ├── auth.js ├── category.js ├── index.js ├── post.js └── users.js /.angulardoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "repoId": "97c5bd95-24d2-47f8-9d72-588c215a0c14", 3 | "lastSync": 0 4 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /client/node_modules 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Didin Jamaludin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MEAN Stack (Angular 8) Tutorial: Build a Simple Blog CMS 2 | 3 | This source codes is part of [MEAN Stack (Angular 8) Tutorial: Build a Simple Blog CMS](https://www.djamware.com/post/5d88cb43e7939eec17dc4c89/mean-stack-angular-8-tutorial-build-a-simple-blog-cms) 4 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var path = require('path'); 3 | var cookieParser = require('cookie-parser'); 4 | var logger = require('morgan'); 5 | var mongoose = require('mongoose'); 6 | var passport = require('passport'); 7 | var auth = require('./routes/auth'); 8 | var category = require('./routes/category'); 9 | var post = require('./routes/post'); 10 | var cors = require('cors') 11 | 12 | mongoose.connect('mongodb://localhost/blog-cms', { 13 | promiseLibrary: require('bluebird'), 14 | useNewUrlParser: true, 15 | useUnifiedTopology: true, 16 | useCreateIndex: true 17 | }).then(() => console.log('connection successful')) 18 | .catch((err) => console.error(err)); 19 | 20 | var indexRouter = require('./routes/index'); 21 | var usersRouter = require('./routes/users'); 22 | 23 | var app = express(); 24 | 25 | app.use(cors()) 26 | app.use(passport.initialize()); 27 | app.use(logger('dev')); 28 | app.use(express.json()); 29 | app.use(express.urlencoded({ extended: false })); 30 | app.use(cookieParser()); 31 | app.use(express.static(path.join(__dirname, 'public'))); 32 | 33 | app.use('/api/auth', auth); 34 | app.use('/api/category', category); 35 | app.use('/api/post', post); 36 | app.use('/api/public', indexRouter); 37 | app.use('/users', usersRouter); 38 | 39 | module.exports = app; 40 | -------------------------------------------------------------------------------- /bin/www: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /** 4 | * Module dependencies. 5 | */ 6 | 7 | var app = require('../app'); 8 | var debug = require('debug')('blog-cms:server'); 9 | var http = require('http'); 10 | 11 | /** 12 | * Get port from environment and store in Express. 13 | */ 14 | 15 | var port = normalizePort(process.env.PORT || '3000'); 16 | app.set('port', port); 17 | 18 | /** 19 | * Create HTTP server. 20 | */ 21 | 22 | var server = http.createServer(app); 23 | 24 | /** 25 | * Listen on provided port, on all network interfaces. 26 | */ 27 | 28 | server.listen(port); 29 | server.on('error', onError); 30 | server.on('listening', onListening); 31 | 32 | /** 33 | * Normalize a port into a number, string, or false. 34 | */ 35 | 36 | function normalizePort(val) { 37 | var port = parseInt(val, 10); 38 | 39 | if (isNaN(port)) { 40 | // named pipe 41 | return val; 42 | } 43 | 44 | if (port >= 0) { 45 | // port number 46 | return port; 47 | } 48 | 49 | return false; 50 | } 51 | 52 | /** 53 | * Event listener for HTTP server "error" event. 54 | */ 55 | 56 | function onError(error) { 57 | if (error.syscall !== 'listen') { 58 | throw error; 59 | } 60 | 61 | var bind = typeof port === 'string' 62 | ? 'Pipe ' + port 63 | : 'Port ' + port; 64 | 65 | // handle specific listen errors with friendly messages 66 | switch (error.code) { 67 | case 'EACCES': 68 | console.error(bind + ' requires elevated privileges'); 69 | process.exit(1); 70 | break; 71 | case 'EADDRINUSE': 72 | console.error(bind + ' is already in use'); 73 | process.exit(1); 74 | break; 75 | default: 76 | throw error; 77 | } 78 | } 79 | 80 | /** 81 | * Event listener for HTTP server "listening" event. 82 | */ 83 | 84 | function onListening() { 85 | var addr = server.address(); 86 | var bind = typeof addr === 'string' 87 | ? 'pipe ' + addr 88 | : 'port ' + addr.port; 89 | debug('Listening on ' + bind); 90 | } 91 | -------------------------------------------------------------------------------- /client/.angulardoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "repoId": "6de99fa0-bcc3-426d-917e-2a1442f57cf2", 3 | "lastSync": 0 4 | } -------------------------------------------------------------------------------- /client/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /client/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | speed-measure-plugin*.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /client/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "client": { 7 | "projectType": "application", 8 | "schematics": { 9 | "@schematics/angular:component": { 10 | "style": "scss" 11 | } 12 | }, 13 | "root": "", 14 | "sourceRoot": "src", 15 | "prefix": "app", 16 | "architect": { 17 | "build": { 18 | "builder": "@angular-devkit/build-angular:browser", 19 | "options": { 20 | "outputPath": "dist/client", 21 | "index": "src/index.html", 22 | "main": "src/main.ts", 23 | "polyfills": "src/polyfills.ts", 24 | "tsConfig": "tsconfig.app.json", 25 | "aot": false, 26 | "assets": [ 27 | "src/favicon.ico", 28 | "src/assets" 29 | ], 30 | "styles": [ 31 | "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css", 32 | "src/styles.scss" 33 | ], 34 | "scripts": [] 35 | }, 36 | "configurations": { 37 | "production": { 38 | "fileReplacements": [ 39 | { 40 | "replace": "src/environments/environment.ts", 41 | "with": "src/environments/environment.prod.ts" 42 | } 43 | ], 44 | "optimization": true, 45 | "outputHashing": "all", 46 | "sourceMap": false, 47 | "extractCss": true, 48 | "namedChunks": false, 49 | "aot": true, 50 | "extractLicenses": true, 51 | "vendorChunk": false, 52 | "buildOptimizer": true, 53 | "budgets": [ 54 | { 55 | "type": "initial", 56 | "maximumWarning": "2mb", 57 | "maximumError": "5mb" 58 | }, 59 | { 60 | "type": "anyComponentStyle", 61 | "maximumWarning": "6kb", 62 | "maximumError": "10kb" 63 | } 64 | ] 65 | } 66 | } 67 | }, 68 | "serve": { 69 | "builder": "@angular-devkit/build-angular:dev-server", 70 | "options": { 71 | "browserTarget": "client:build" 72 | }, 73 | "configurations": { 74 | "production": { 75 | "browserTarget": "client:build:production" 76 | } 77 | } 78 | }, 79 | "extract-i18n": { 80 | "builder": "@angular-devkit/build-angular:extract-i18n", 81 | "options": { 82 | "browserTarget": "client:build" 83 | } 84 | }, 85 | "test": { 86 | "builder": "@angular-devkit/build-angular:karma", 87 | "options": { 88 | "main": "src/test.ts", 89 | "polyfills": "src/polyfills.ts", 90 | "tsConfig": "tsconfig.spec.json", 91 | "karmaConfig": "karma.conf.js", 92 | "assets": [ 93 | "src/favicon.ico", 94 | "src/assets" 95 | ], 96 | "styles": [ 97 | "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css", 98 | "src/styles.scss" 99 | ], 100 | "scripts": [] 101 | } 102 | }, 103 | "lint": { 104 | "builder": "@angular-devkit/build-angular:tslint", 105 | "options": { 106 | "tsConfig": [ 107 | "tsconfig.app.json", 108 | "tsconfig.spec.json", 109 | "e2e/tsconfig.json" 110 | ], 111 | "exclude": [ 112 | "**/node_modules/**" 113 | ] 114 | } 115 | }, 116 | "e2e": { 117 | "builder": "@angular-devkit/build-angular:protractor", 118 | "options": { 119 | "protractorConfig": "e2e/protractor.conf.js", 120 | "devServerTarget": "client:serve" 121 | }, 122 | "configurations": { 123 | "production": { 124 | "devServerTarget": "client:serve:production" 125 | } 126 | } 127 | } 128 | } 129 | } 130 | }, 131 | "defaultProject": "client" 132 | } -------------------------------------------------------------------------------- /client/browserslist: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. -------------------------------------------------------------------------------- /client/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | 'browserName': 'chrome' 17 | }, 18 | directConnect: true, 19 | baseUrl: 'http://localhost:4200/', 20 | framework: 'jasmine', 21 | jasmineNodeOpts: { 22 | showColors: true, 23 | defaultTimeoutInterval: 30000, 24 | print: function() {} 25 | }, 26 | onPrepare() { 27 | require('ts-node').register({ 28 | project: require('path').join(__dirname, './tsconfig.json') 29 | }); 30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 31 | } 32 | }; -------------------------------------------------------------------------------- /client/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', () => { 12 | page.navigateTo(); 13 | expect(page.getTitleText()).toEqual('client app is running!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /client/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText() { 9 | return element(by.css('app-root .content span')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /client/e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /client/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, './coverage/client'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "client", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "~8.2.7", 15 | "@angular/cdk": "~8.2.0", 16 | "@angular/common": "~8.2.7", 17 | "@angular/compiler": "~8.2.7", 18 | "@angular/core": "~11.0.5", 19 | "@angular/forms": "~8.2.7", 20 | "@angular/material": "^8.2.0", 21 | "@angular/platform-browser": "~8.2.7", 22 | "@angular/platform-browser-dynamic": "~8.2.7", 23 | "@angular/router": "~8.2.7", 24 | "ckeditor4-angular": "^1.0.0-beta.2", 25 | "hammerjs": "^2.0.8", 26 | "mat-contenteditable": "^8.0.2", 27 | "rxjs": "~6.4.0", 28 | "tslib": "^1.10.0", 29 | "zone.js": "~0.9.1" 30 | }, 31 | "devDependencies": { 32 | "@angular-devkit/build-angular": "~15.0.3", 33 | "@angular/cli": "~15.0.3", 34 | "@angular/compiler-cli": "~8.2.7", 35 | "@angular/language-service": "~8.2.7", 36 | "@types/node": "~8.9.4", 37 | "@types/jasmine": "~3.3.8", 38 | "@types/jasminewd2": "~2.0.3", 39 | "codelyzer": "^5.0.0", 40 | "jasmine-core": "~3.4.0", 41 | "jasmine-spec-reporter": "~4.2.1", 42 | "karma": "~6.4.1", 43 | "karma-chrome-launcher": "~2.2.0", 44 | "karma-coverage-istanbul-reporter": "~2.0.1", 45 | "karma-jasmine": "~2.0.1", 46 | "karma-jasmine-html-reporter": "^1.4.0", 47 | "protractor": "~5.4.2", 48 | "ts-node": "~7.0.0", 49 | "tslint": "~5.15.0", 50 | "typescript": "~3.5.3" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /client/src/app/admin/admin.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | Populate the Category and Post data by click on the Menu. 5 | 6 | 7 |
8 | -------------------------------------------------------------------------------- /client/src/app/admin/admin.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/didinj/mean-stack-angular-8-blog-cms/bc74491deaef105a1534fc300ba0869d180c5b48/client/src/app/admin/admin.component.scss -------------------------------------------------------------------------------- /client/src/app/admin/admin.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { AdminComponent } from './admin.component'; 4 | 5 | describe('AdminComponent', () => { 6 | let component: AdminComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ AdminComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(AdminComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /client/src/app/admin/admin.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-admin', 5 | templateUrl: './admin.component.html', 6 | styleUrls: ['./admin.component.scss'] 7 | }) 8 | export class AdminComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /client/src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | import { LoginComponent } from './auth/login/login.component'; 4 | import { RegisterComponent } from './auth/register/register.component'; 5 | import { HomeComponent } from './home/home.component'; 6 | import { DetailsComponent } from './details/details.component'; 7 | import { CategoryComponent } from './category/category.component'; 8 | import { PostComponent } from './post/post.component'; 9 | import { CategoryDetailsComponent } from './category/category-details/category-details.component'; 10 | import { CategoryAddComponent } from './category/category-add/category-add.component'; 11 | import { CategoryEditComponent } from './category/category-edit/category-edit.component'; 12 | import { PostDetailsComponent } from './post/post-details/post-details.component'; 13 | import { PostAddComponent } from './post/post-add/post-add.component'; 14 | import { PostEditComponent } from './post/post-edit/post-edit.component'; 15 | import { BycategoryComponent } from './bycategory/bycategory.component'; 16 | import { AuthGuard } from './auth/auth.guard'; 17 | import { AdminComponent } from './admin/admin.component'; 18 | 19 | 20 | const routes: Routes = [ 21 | { 22 | path: '', 23 | redirectTo: 'home', 24 | pathMatch: 'full' 25 | }, 26 | { 27 | path: 'home', 28 | component: HomeComponent, 29 | data: { title: 'Blog Home' } 30 | }, 31 | { 32 | path: 'admin', 33 | canActivate: [AuthGuard], 34 | component: AdminComponent, 35 | data: { title: 'Blog Admin' } 36 | }, 37 | { 38 | path: 'bycategory/:id', 39 | component: BycategoryComponent, 40 | data: { title: 'Post by Category' } 41 | }, 42 | { 43 | path: 'details/:id', 44 | component: DetailsComponent, 45 | data: { title: 'Show Post Details' } 46 | }, 47 | { 48 | path: 'login', 49 | component: LoginComponent, 50 | data: { title: 'Login' } 51 | }, 52 | { 53 | path: 'register', 54 | component: RegisterComponent, 55 | data: { title: 'Register' } 56 | }, 57 | { 58 | path: 'category', 59 | canActivate: [AuthGuard], 60 | component: CategoryComponent, 61 | data: { title: 'Category' } 62 | }, 63 | { 64 | path: 'category/details/:id', 65 | canActivate: [AuthGuard], 66 | component: CategoryDetailsComponent, 67 | data: { title: 'Category Details' } 68 | }, 69 | { 70 | path: 'category/add', 71 | canActivate: [AuthGuard], 72 | component: CategoryAddComponent, 73 | data: { title: 'Category Add' } 74 | }, 75 | { 76 | path: 'category/edit/:id', 77 | canActivate: [AuthGuard], 78 | component: CategoryEditComponent, 79 | data: { title: 'Category Edit' } 80 | }, 81 | { 82 | path: 'post', 83 | canActivate: [AuthGuard], 84 | component: PostComponent, 85 | data: { title: 'Post' } 86 | }, 87 | { 88 | path: 'post/details/:id', 89 | canActivate: [AuthGuard], 90 | component: PostDetailsComponent, 91 | data: { title: 'Post Details' } 92 | }, 93 | { 94 | path: 'post/add', 95 | canActivate: [AuthGuard], 96 | component: PostAddComponent, 97 | data: { title: 'Post Add' } 98 | }, 99 | { 100 | path: 'post/edit/:id', 101 | canActivate: [AuthGuard], 102 | component: PostEditComponent, 103 | data: { title: 'Post Edit' } 104 | } 105 | ]; 106 | 107 | @NgModule({ 108 | imports: [RouterModule.forRoot(routes)], 109 | exports: [RouterModule] 110 | }) 111 | export class AppRoutingModule { } 112 | -------------------------------------------------------------------------------- /client/src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 | 7 |
8 |
9 | 10 | 11 | 12 | 13 |
14 |
15 |
16 | 17 | -------------------------------------------------------------------------------- /client/src/app/app.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/didinj/mean-stack-angular-8-blog-cms/bc74491deaef105a1534fc300ba0869d180c5b48/client/src/app/app.component.scss -------------------------------------------------------------------------------- /client/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { RouterTestingModule } from '@angular/router/testing'; 3 | import { AppComponent } from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async(() => { 7 | TestBed.configureTestingModule({ 8 | imports: [ 9 | RouterTestingModule 10 | ], 11 | declarations: [ 12 | AppComponent 13 | ], 14 | }).compileComponents(); 15 | })); 16 | 17 | it('should create the app', () => { 18 | const fixture = TestBed.createComponent(AppComponent); 19 | const app = fixture.debugElement.componentInstance; 20 | expect(app).toBeTruthy(); 21 | }); 22 | 23 | it(`should have as title 'client'`, () => { 24 | const fixture = TestBed.createComponent(AppComponent); 25 | const app = fixture.debugElement.componentInstance; 26 | expect(app.title).toEqual('client'); 27 | }); 28 | 29 | it('should render title', () => { 30 | const fixture = TestBed.createComponent(AppComponent); 31 | fixture.detectChanges(); 32 | const compiled = fixture.debugElement.nativeElement; 33 | expect(compiled.querySelector('.content span').textContent).toContain('client app is running!'); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /client/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Router } from '@angular/router'; 3 | import { Category } from './category/category'; 4 | import { HomeService } from './home.service'; 5 | import { AuthService } from './auth.service'; 6 | 7 | @Component({ 8 | selector: 'app-root', 9 | templateUrl: './app.component.html', 10 | styleUrls: ['./app.component.scss'] 11 | }) 12 | export class AppComponent implements OnInit { 13 | title = 'client'; 14 | categories: Category[] = []; 15 | loginStatus = false; 16 | 17 | constructor(private api: HomeService, private authService: AuthService, private router: Router) { } 18 | 19 | ngOnInit() { 20 | this.authService.isLoggedIn.subscribe((status: any) => { 21 | console.log(status); 22 | if (status === true) { 23 | this.loginStatus = true; 24 | } else { 25 | this.loginStatus = false; 26 | } 27 | }); 28 | this.api.getCategories() 29 | .subscribe((res: any) => { 30 | this.categories = res; 31 | console.log(this.categories); 32 | }, err => { 33 | console.log(err); 34 | }); 35 | } 36 | 37 | logout() { 38 | this.authService.logout() 39 | .subscribe((res: any) => { 40 | this.router.navigate(['/']); 41 | }, err => { 42 | console.log(err); 43 | }); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /client/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | 4 | import { AppRoutingModule } from './app-routing.module'; 5 | import { AppComponent } from './app.component'; 6 | import { LoginComponent } from './auth/login/login.component'; 7 | import { RegisterComponent } from './auth/register/register.component'; 8 | import { HomeComponent } from './home/home.component'; 9 | import { DetailsComponent } from './details/details.component'; 10 | import { CategoryComponent } from './category/category.component'; 11 | import { PostComponent } from './post/post.component'; 12 | import { CategoryDetailsComponent } from './category/category-details/category-details.component'; 13 | import { CategoryAddComponent } from './category/category-add/category-add.component'; 14 | import { CategoryEditComponent } from './category/category-edit/category-edit.component'; 15 | import { PostDetailsComponent } from './post/post-details/post-details.component'; 16 | import { PostAddComponent } from './post/post-add/post-add.component'; 17 | import { PostEditComponent } from './post/post-edit/post-edit.component'; 18 | 19 | import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http'; 20 | import { TokenInterceptor } from './interceptors/token.interceptor'; 21 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 22 | import { 23 | MatInputModule, 24 | MatPaginatorModule, 25 | MatProgressSpinnerModule, 26 | MatSortModule, 27 | MatTableModule, 28 | MatIconModule, 29 | MatButtonModule, 30 | MatCardModule, 31 | MatFormFieldModule, 32 | MatMenuModule, 33 | MatToolbarModule, 34 | MatSelectModule, 35 | MatOptionModule, 36 | MatGridListModule } from '@angular/material'; 37 | import { FormsModule, ReactiveFormsModule } from '@angular/forms'; 38 | import { BycategoryComponent } from './bycategory/bycategory.component'; 39 | import { CKEditorModule } from 'ckeditor4-angular'; 40 | import { MatContenteditableModule } from 'mat-contenteditable'; 41 | import { AdminComponent } from './admin/admin.component'; 42 | 43 | @NgModule({ 44 | declarations: [ 45 | AppComponent, 46 | LoginComponent, 47 | RegisterComponent, 48 | HomeComponent, 49 | DetailsComponent, 50 | CategoryComponent, 51 | PostComponent, 52 | CategoryDetailsComponent, 53 | CategoryAddComponent, 54 | CategoryEditComponent, 55 | PostDetailsComponent, 56 | PostAddComponent, 57 | PostEditComponent, 58 | BycategoryComponent, 59 | AdminComponent 60 | ], 61 | imports: [ 62 | BrowserModule, 63 | AppRoutingModule, 64 | HttpClientModule, 65 | BrowserAnimationsModule, 66 | FormsModule, 67 | ReactiveFormsModule, 68 | MatInputModule, 69 | MatTableModule, 70 | MatPaginatorModule, 71 | MatSortModule, 72 | MatProgressSpinnerModule, 73 | MatIconModule, 74 | MatButtonModule, 75 | MatCardModule, 76 | MatFormFieldModule, 77 | MatMenuModule, 78 | MatToolbarModule, 79 | MatGridListModule, 80 | MatSelectModule, 81 | MatOptionModule, 82 | CKEditorModule, 83 | MatContenteditableModule 84 | ], 85 | providers: [ 86 | { 87 | provide: HTTP_INTERCEPTORS, 88 | useClass: TokenInterceptor, 89 | multi: true 90 | } 91 | ], 92 | bootstrap: [AppComponent] 93 | }) 94 | export class AppModule { } 95 | -------------------------------------------------------------------------------- /client/src/app/auth.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | 3 | import { AuthService } from './auth.service'; 4 | 5 | describe('AuthService', () => { 6 | beforeEach(() => TestBed.configureTestingModule({})); 7 | 8 | it('should be created', () => { 9 | const service: AuthService = TestBed.get(AuthService); 10 | expect(service).toBeTruthy(); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /client/src/app/auth.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable, Output, EventEmitter } from '@angular/core'; 2 | import { HttpClient } from '@angular/common/http'; 3 | import { Observable, of } from 'rxjs'; 4 | import { catchError, tap } from 'rxjs/operators'; 5 | 6 | const apiUrl = 'http://localhost:3000/api/auth/'; 7 | 8 | @Injectable({ 9 | providedIn: 'root' 10 | }) 11 | export class AuthService { 12 | 13 | @Output() isLoggedIn: EventEmitter = new EventEmitter(); 14 | loggedInStatus = false; 15 | redirectUrl: string; 16 | 17 | constructor(private http: HttpClient) { } 18 | 19 | login(data: any): Observable { 20 | return this.http.post(apiUrl + 'login', data) 21 | .pipe( 22 | tap(_ => { 23 | this.isLoggedIn.emit(true); 24 | this.loggedInStatus = true; 25 | }), 26 | catchError(this.handleError('login', [])) 27 | ); 28 | } 29 | 30 | logout(): Observable { 31 | return this.http.post(apiUrl + 'logout', {}) 32 | .pipe( 33 | tap(_ => { 34 | this.isLoggedIn.emit(false); 35 | this.loggedInStatus = false; 36 | }), 37 | catchError(this.handleError('logout', [])) 38 | ); 39 | } 40 | 41 | register(data: any): Observable { 42 | return this.http.post(apiUrl + 'register', data) 43 | .pipe( 44 | tap(_ => this.log('login')), 45 | catchError(this.handleError('login', [])) 46 | ); 47 | } 48 | 49 | private handleError(operation = 'operation', result?: T) { 50 | return (error: any): Observable => { 51 | 52 | console.error(error); // log to console instead 53 | this.log(`${operation} failed: ${error.message}`); 54 | 55 | return of(result as T); 56 | }; 57 | } 58 | 59 | private log(message: string) { 60 | console.log(message); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /client/src/app/auth/auth.guard.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async, inject } from '@angular/core/testing'; 2 | 3 | import { AuthGuard } from './auth.guard'; 4 | 5 | describe('AuthGuard', () => { 6 | beforeEach(() => { 7 | TestBed.configureTestingModule({ 8 | providers: [AuthGuard] 9 | }); 10 | }); 11 | 12 | it('should ...', inject([AuthGuard], (guard: AuthGuard) => { 13 | expect(guard).toBeTruthy(); 14 | })); 15 | }); 16 | -------------------------------------------------------------------------------- /client/src/app/auth/auth.guard.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router'; 3 | import { AuthService } from '../auth.service'; 4 | 5 | @Injectable({ 6 | providedIn: 'root' 7 | }) 8 | export class AuthGuard implements CanActivate { 9 | 10 | constructor(private authService: AuthService, private router: Router) {} 11 | 12 | canActivate( 13 | next: ActivatedRouteSnapshot, 14 | state: RouterStateSnapshot): boolean { 15 | const url: string = state.url; 16 | 17 | return this.checkLogin(url); 18 | } 19 | 20 | checkLogin(url: string): boolean { 21 | if (this.authService.loggedInStatus) { return true; } 22 | 23 | // Store the attempted URL for redirecting 24 | this.authService.redirectUrl = url; 25 | 26 | // Navigate to the login page with extras 27 | this.router.navigate(['/login']); 28 | return false; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /client/src/app/auth/login/login.component.html: -------------------------------------------------------------------------------- 1 |
2 |
4 | 5 |
6 | 7 |
8 | 9 | 11 | 12 | Please enter your username 13 | 14 | 15 | 16 | 18 | 19 | Please enter your password 20 | 21 | 22 |
23 | 24 |
25 |
26 | 27 |
28 |
29 |
30 |
31 | -------------------------------------------------------------------------------- /client/src/app/auth/login/login.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/didinj/mean-stack-angular-8-blog-cms/bc74491deaef105a1534fc300ba0869d180c5b48/client/src/app/auth/login/login.component.scss -------------------------------------------------------------------------------- /client/src/app/auth/login/login.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { LoginComponent } from './login.component'; 4 | 5 | describe('LoginComponent', () => { 6 | let component: LoginComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ LoginComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(LoginComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /client/src/app/auth/login/login.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { FormControl, FormGroupDirective, FormBuilder, FormGroup, NgForm, Validators } from '@angular/forms'; 3 | import { AuthService } from '../../auth.service'; 4 | import { Router } from '@angular/router'; 5 | import { ErrorStateMatcher } from '@angular/material/core'; 6 | 7 | /** Error when invalid control is dirty, touched, or submitted. */ 8 | export class MyErrorStateMatcher implements ErrorStateMatcher { 9 | isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean { 10 | const isSubmitted = form && form.submitted; 11 | return !!(control && control.invalid && (control.dirty || control.touched || isSubmitted)); 12 | } 13 | } 14 | 15 | @Component({ 16 | selector: 'app-login', 17 | templateUrl: './login.component.html', 18 | styleUrls: ['./login.component.scss'] 19 | }) 20 | export class LoginComponent implements OnInit { 21 | 22 | loginForm: FormGroup; 23 | username = ''; 24 | password = ''; 25 | matcher = new MyErrorStateMatcher(); 26 | isLoadingResults = false; 27 | 28 | constructor(private formBuilder: FormBuilder, private router: Router, private authService: AuthService) { } 29 | 30 | ngOnInit() { 31 | this.loginForm = this.formBuilder.group({ 32 | username : [null, Validators.required], 33 | password : [null, Validators.required] 34 | }); 35 | } 36 | 37 | onFormSubmit(form: NgForm) { 38 | this.authService.login(form) 39 | .subscribe(res => { 40 | console.log(res); 41 | if (res.token) { 42 | localStorage.setItem('token', res.token); 43 | this.router.navigate(['admin']); 44 | } 45 | }, (err) => { 46 | console.log(err); 47 | }); 48 | } 49 | 50 | register() { 51 | this.router.navigate(['register']); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /client/src/app/auth/register/register.component.html: -------------------------------------------------------------------------------- 1 |
2 |
4 | 5 |
6 | 7 |
8 | 9 | 11 | 12 | Please enter your Full Name 13 | 14 | 15 | 16 | 18 | 19 | Please enter your username 20 | 21 | 22 | 23 | 25 | 26 | Please enter your password 27 | 28 | 29 |
30 | 31 |
32 |
33 |
34 |
35 | -------------------------------------------------------------------------------- /client/src/app/auth/register/register.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/didinj/mean-stack-angular-8-blog-cms/bc74491deaef105a1534fc300ba0869d180c5b48/client/src/app/auth/register/register.component.scss -------------------------------------------------------------------------------- /client/src/app/auth/register/register.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { RegisterComponent } from './register.component'; 4 | 5 | describe('RegisterComponent', () => { 6 | let component: RegisterComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ RegisterComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(RegisterComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /client/src/app/auth/register/register.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { FormControl, FormGroupDirective, FormBuilder, FormGroup, NgForm, Validators } from '@angular/forms'; 3 | import { AuthService } from '../../auth.service'; 4 | import { Router } from '@angular/router'; 5 | import { ErrorStateMatcher } from '@angular/material/core'; 6 | 7 | /** Error when invalid control is dirty, touched, or submitted. */ 8 | export class MyErrorStateMatcher implements ErrorStateMatcher { 9 | isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean { 10 | const isSubmitted = form && form.submitted; 11 | return !!(control && control.invalid && (control.dirty || control.touched || isSubmitted)); 12 | } 13 | } 14 | 15 | @Component({ 16 | selector: 'app-register', 17 | templateUrl: './register.component.html', 18 | styleUrls: ['./register.component.scss'] 19 | }) 20 | export class RegisterComponent implements OnInit { 21 | 22 | registerForm: FormGroup; 23 | fullName = ''; 24 | username = ''; 25 | password = ''; 26 | isLoadingResults = false; 27 | matcher = new MyErrorStateMatcher(); 28 | 29 | constructor(private formBuilder: FormBuilder, private router: Router, private authService: AuthService) { } 30 | 31 | ngOnInit() { 32 | this.registerForm = this.formBuilder.group({ 33 | fullName : [null, Validators.required], 34 | username : [null, Validators.required], 35 | password : [null, Validators.required] 36 | }); 37 | } 38 | 39 | onFormSubmit(form: NgForm) { 40 | this.authService.register(form) 41 | .subscribe(res => { 42 | this.router.navigate(['login']); 43 | }, (err) => { 44 | console.log(err); 45 | alert(err.error); 46 | }); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /client/src/app/bycategory/bycategory.component.html: -------------------------------------------------------------------------------- 1 |
2 |
4 | 5 |
6 | 7 | 8 | 9 | 10 |
11 | {{post.postTitle}} 12 | {{post.updated}} 13 |
14 | Photo of a Shiba Inu 15 | 16 | {{post.postDesc}} 17 | 18 |
19 |
20 |
21 |
22 | -------------------------------------------------------------------------------- /client/src/app/bycategory/bycategory.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/didinj/mean-stack-angular-8-blog-cms/bc74491deaef105a1534fc300ba0869d180c5b48/client/src/app/bycategory/bycategory.component.scss -------------------------------------------------------------------------------- /client/src/app/bycategory/bycategory.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { BycategoryComponent } from './bycategory.component'; 4 | 5 | describe('BycategoryComponent', () => { 6 | let component: BycategoryComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ BycategoryComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(BycategoryComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /client/src/app/bycategory/bycategory.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { ActivatedRoute, Router } from '@angular/router'; 3 | import { Post } from '../post/post'; 4 | import { HomeService } from '../home.service'; 5 | 6 | @Component({ 7 | selector: 'app-bycategory', 8 | templateUrl: './bycategory.component.html', 9 | styleUrls: ['./bycategory.component.scss'] 10 | }) 11 | export class BycategoryComponent implements OnInit { 12 | 13 | posts: Post[] = []; 14 | isLoadingResults = true; 15 | 16 | constructor(private route: ActivatedRoute, private api: HomeService) { } 17 | 18 | ngOnInit() { 19 | this.route.params.subscribe(params => { 20 | this.getPostsByCategory(this.route.snapshot.params.id); 21 | }); 22 | } 23 | 24 | getPostsByCategory(id: any) { 25 | this.posts = []; 26 | this.api.getPostsByCategory(id) 27 | .subscribe((res: any) => { 28 | this.posts = res; 29 | console.log(this.posts); 30 | this.isLoadingResults = false; 31 | }, err => { 32 | console.log(err); 33 | this.isLoadingResults = false; 34 | }); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /client/src/app/category.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | 3 | import { CategoryService } from './category.service'; 4 | 5 | describe('CategoryService', () => { 6 | beforeEach(() => TestBed.configureTestingModule({})); 7 | 8 | it('should be created', () => { 9 | const service: CategoryService = TestBed.get(CategoryService); 10 | expect(service).toBeTruthy(); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /client/src/app/category.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient } from '@angular/common/http'; 3 | import { Observable, of } from 'rxjs'; 4 | import { catchError, tap } from 'rxjs/operators'; 5 | import { Category } from './category/category'; 6 | 7 | const apiUrl = 'http://localhost:3000/api/category/'; 8 | 9 | @Injectable({ 10 | providedIn: 'root' 11 | }) 12 | export class CategoryService { 13 | 14 | constructor(private http: HttpClient) { } 15 | 16 | getCategories(): Observable { 17 | return this.http.get(apiUrl) 18 | .pipe( 19 | tap(_ => this.log('fetched Categories')), 20 | catchError(this.handleError('getCategories', [])) 21 | ); 22 | } 23 | 24 | getCategory(id: any): Observable { 25 | const url = `${apiUrl}/${id}`; 26 | return this.http.get(url).pipe( 27 | tap(_ => console.log(`fetched category by id=${id}`)), 28 | catchError(this.handleError(`getCategory id=${id}`)) 29 | ); 30 | } 31 | 32 | addCategory(category: Category): Observable { 33 | return this.http.post(apiUrl, category).pipe( 34 | tap((prod: Category) => console.log(`added category w/ id=${category.id}`)), 35 | catchError(this.handleError('addCategory')) 36 | ); 37 | } 38 | 39 | updateCategory(id: any, category: Category): Observable { 40 | const url = `${apiUrl}/${id}`; 41 | return this.http.put(url, category).pipe( 42 | tap(_ => console.log(`updated category id=${id}`)), 43 | catchError(this.handleError('updateCategory')) 44 | ); 45 | } 46 | 47 | deleteCategory(id: any): Observable { 48 | const url = `${apiUrl}/${id}`; 49 | return this.http.delete(url).pipe( 50 | tap(_ => console.log(`deleted category id=${id}`)), 51 | catchError(this.handleError('deleteCategory')) 52 | ); 53 | } 54 | 55 | private handleError(operation = 'operation', result?: T) { 56 | return (error: any): Observable => { 57 | 58 | console.error(error); // log to console instead 59 | this.log(`${operation} failed: ${error.message}`); 60 | 61 | return of(result as T); 62 | }; 63 | } 64 | 65 | private log(message: string) { 66 | console.log(message); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /client/src/app/category/category-add/category-add.component.html: -------------------------------------------------------------------------------- 1 |
2 |
4 | 5 |
6 |
7 | list 8 |
9 | 10 |
11 | 12 | 14 | 15 | Please enter Category Name 16 | 17 | 18 | 19 | 21 | 22 | Please enter Category Description 23 | 24 | 25 | 26 | 28 | 29 | Please enter Category Image URL 30 | 31 | 32 | 33 | 34 | 35 | Please enter Category Description 36 | 37 | 38 |
39 | 40 |
41 |
42 |
43 |
44 | -------------------------------------------------------------------------------- /client/src/app/category/category-add/category-add.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/didinj/mean-stack-angular-8-blog-cms/bc74491deaef105a1534fc300ba0869d180c5b48/client/src/app/category/category-add/category-add.component.scss -------------------------------------------------------------------------------- /client/src/app/category/category-add/category-add.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { CategoryAddComponent } from './category-add.component'; 4 | 5 | describe('CategoryAddComponent', () => { 6 | let component: CategoryAddComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ CategoryAddComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(CategoryAddComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /client/src/app/category/category-add/category-add.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Router } from '@angular/router'; 3 | import { CategoryService } from '../../category.service'; 4 | import { FormControl, FormGroupDirective, FormBuilder, FormGroup, NgForm, Validators } from '@angular/forms'; 5 | import { ErrorStateMatcher } from '@angular/material/core'; 6 | 7 | /** Error when invalid control is dirty, touched, or submitted. */ 8 | export class MyErrorStateMatcher implements ErrorStateMatcher { 9 | isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean { 10 | const isSubmitted = form && form.submitted; 11 | return !!(control && control.invalid && (control.dirty || control.touched || isSubmitted)); 12 | } 13 | } 14 | 15 | @Component({ 16 | selector: 'app-category-add', 17 | templateUrl: './category-add.component.html', 18 | styleUrls: ['./category-add.component.scss'] 19 | }) 20 | export class CategoryAddComponent implements OnInit { 21 | 22 | categoryForm: FormGroup; 23 | catName = ''; 24 | catDesc = ''; 25 | catImgUrl = ''; 26 | catContent = ''; 27 | isLoadingResults = false; 28 | matcher = new MyErrorStateMatcher(); 29 | 30 | constructor(private router: Router, private api: CategoryService, private formBuilder: FormBuilder) { } 31 | 32 | ngOnInit() { 33 | this.categoryForm = this.formBuilder.group({ 34 | catName : [null, Validators.required], 35 | catDesc : [null, Validators.required], 36 | catImgUrl : [null, Validators.required], 37 | catContent : [null, Validators.required] 38 | }); 39 | } 40 | 41 | onFormSubmit() { 42 | this.isLoadingResults = true; 43 | this.api.addCategory(this.categoryForm.value) 44 | .subscribe((res: any) => { 45 | const id = res._id; 46 | this.isLoadingResults = false; 47 | this.router.navigate(['/category/details', id]); 48 | }, (err: any) => { 49 | console.log(err); 50 | this.isLoadingResults = false; 51 | }); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /client/src/app/category/category-details/category-details.component.html: -------------------------------------------------------------------------------- 1 |
2 |
4 | 5 |
6 |
7 | list 8 |
9 | 10 | 11 |

{{category.catName}}

12 | {{category.catDesc}} 13 |
14 | {{category.catName}} 15 | 16 |
17 |
Category Content:
18 |
19 |
Updated At:
20 |
{{category.updated | date}}
21 |
22 |
23 | 24 | edit 25 | delete 26 | 27 |
28 |
29 | -------------------------------------------------------------------------------- /client/src/app/category/category-details/category-details.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/didinj/mean-stack-angular-8-blog-cms/bc74491deaef105a1534fc300ba0869d180c5b48/client/src/app/category/category-details/category-details.component.scss -------------------------------------------------------------------------------- /client/src/app/category/category-details/category-details.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { CategoryDetailsComponent } from './category-details.component'; 4 | 5 | describe('CategoryDetailsComponent', () => { 6 | let component: CategoryDetailsComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ CategoryDetailsComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(CategoryDetailsComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /client/src/app/category/category-details/category-details.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { ActivatedRoute, Router } from '@angular/router'; 3 | import { CategoryService } from './../../category.service'; 4 | import { Category } from '../category'; 5 | 6 | @Component({ 7 | selector: 'app-category-details', 8 | templateUrl: './category-details.component.html', 9 | styleUrls: ['./category-details.component.scss'] 10 | }) 11 | export class CategoryDetailsComponent implements OnInit { 12 | 13 | category: Category = { id: null, catName: '', catDesc: '', catImgUrl: '', catContent: '', updated: null }; 14 | isLoadingResults = true; 15 | 16 | constructor(private route: ActivatedRoute, private api: CategoryService, private router: Router) { } 17 | 18 | ngOnInit() { 19 | this.getCategoryDetails(this.route.snapshot.params.id); 20 | } 21 | 22 | getCategoryDetails(id: any) { 23 | this.api.getCategory(id) 24 | .subscribe((data: any) => { 25 | this.category = data; 26 | this.category.id = data._id; 27 | console.log(this.category); 28 | this.isLoadingResults = false; 29 | }); 30 | } 31 | 32 | deleteCategory(id: any) { 33 | this.isLoadingResults = true; 34 | this.api.deleteCategory(id) 35 | .subscribe(res => { 36 | this.isLoadingResults = false; 37 | this.router.navigate(['/category']); 38 | }, (err) => { 39 | console.log(err); 40 | this.isLoadingResults = false; 41 | } 42 | ); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /client/src/app/category/category-edit/category-edit.component.html: -------------------------------------------------------------------------------- 1 |
2 |
4 | 5 |
6 |
7 | list 8 |
9 | 10 |
11 | 12 | 14 | 15 | Please enter Category Name 16 | 17 | 18 | 19 | 21 | 22 | Please enter Category Description 23 | 24 | 25 | 26 | 28 | 29 | Please enter Category Image URL 30 | 31 | 32 | 33 | 34 | 35 | Please enter Category Description 36 | 37 | 38 |
39 | 40 |
41 |
42 |
43 |
44 | -------------------------------------------------------------------------------- /client/src/app/category/category-edit/category-edit.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/didinj/mean-stack-angular-8-blog-cms/bc74491deaef105a1534fc300ba0869d180c5b48/client/src/app/category/category-edit/category-edit.component.scss -------------------------------------------------------------------------------- /client/src/app/category/category-edit/category-edit.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { CategoryEditComponent } from './category-edit.component'; 4 | 5 | describe('CategoryEditComponent', () => { 6 | let component: CategoryEditComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ CategoryEditComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(CategoryEditComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /client/src/app/category/category-edit/category-edit.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Router, ActivatedRoute } from '@angular/router'; 3 | import { CategoryService } from '../../category.service'; 4 | import { FormControl, FormGroupDirective, FormBuilder, FormGroup, NgForm, Validators } from '@angular/forms'; 5 | import { ErrorStateMatcher } from '@angular/material/core'; 6 | 7 | /** Error when invalid control is dirty, touched, or submitted. */ 8 | export class MyErrorStateMatcher implements ErrorStateMatcher { 9 | isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean { 10 | const isSubmitted = form && form.submitted; 11 | return !!(control && control.invalid && (control.dirty || control.touched || isSubmitted)); 12 | } 13 | } 14 | 15 | @Component({ 16 | selector: 'app-category-edit', 17 | templateUrl: './category-edit.component.html', 18 | styleUrls: ['./category-edit.component.scss'] 19 | }) 20 | export class CategoryEditComponent implements OnInit { 21 | 22 | categoryForm: FormGroup; 23 | id = ''; 24 | catName = ''; 25 | catDesc = ''; 26 | catImgUrl = ''; 27 | catContent = ''; 28 | updated: Date = null; 29 | isLoadingResults = false; 30 | matcher = new MyErrorStateMatcher(); 31 | 32 | constructor(private router: Router, private route: ActivatedRoute, private api: CategoryService, private formBuilder: FormBuilder) { } 33 | 34 | ngOnInit() { 35 | this.getCategory(this.route.snapshot.params.id); 36 | this.categoryForm = this.formBuilder.group({ 37 | catName : [null, Validators.required], 38 | catDesc : [null, Validators.required], 39 | catImgUrl : [null, Validators.required], 40 | catContent : [null, Validators.required] 41 | }); 42 | } 43 | 44 | getCategory(id: any) { 45 | this.api.getCategory(id).subscribe((data: any) => { 46 | this.id = data._id; 47 | this.categoryForm.setValue({ 48 | catName: data.catName, 49 | catDesc: data.catDesc, 50 | catImgUrl: data.catImgUrl, 51 | catContent: data.catContent 52 | }); 53 | }); 54 | } 55 | 56 | onFormSubmit() { 57 | this.isLoadingResults = true; 58 | this.api.updateCategory(this.id, this.categoryForm.value) 59 | .subscribe((res: any) => { 60 | const id = res._id; 61 | this.isLoadingResults = false; 62 | this.router.navigate(['/category/details', id]); 63 | }, (err: any) => { 64 | console.log(err); 65 | this.isLoadingResults = false; 66 | } 67 | ); 68 | } 69 | 70 | categoryDetails() { 71 | this.router.navigate(['/category/details', this.id]); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /client/src/app/category/category.component.html: -------------------------------------------------------------------------------- 1 |
2 |
4 | 5 |
6 |
7 | add 8 |
9 |
10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
Category Name{{row.catName}}Category Description{{row.catDesc}}
28 |
29 |
30 | -------------------------------------------------------------------------------- /client/src/app/category/category.component.scss: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /client/src/app/category/category.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { CategoryComponent } from './category.component'; 4 | 5 | describe('CategoryComponent', () => { 6 | let component: CategoryComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ CategoryComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(CategoryComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /client/src/app/category/category.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { CategoryService } from '../category.service'; 3 | import { Category } from './category'; 4 | 5 | @Component({ 6 | selector: 'app-category', 7 | templateUrl: './category.component.html', 8 | styleUrls: ['./category.component.scss'] 9 | }) 10 | export class CategoryComponent implements OnInit { 11 | 12 | displayedColumns: string[] = ['catName', 'catDesc']; 13 | data: Category[] = []; 14 | isLoadingResults = true; 15 | 16 | constructor(private api: CategoryService) { } 17 | 18 | ngOnInit() { 19 | this.api.getCategories() 20 | .subscribe((res: any) => { 21 | this.data = res; 22 | console.log(this.data); 23 | this.isLoadingResults = false; 24 | }, err => { 25 | console.log(err); 26 | this.isLoadingResults = false; 27 | }); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /client/src/app/category/category.ts: -------------------------------------------------------------------------------- 1 | export class Category { 2 | id: number; 3 | catName: string; 4 | catDesc: string; 5 | catImgUrl: string; 6 | catContent: string; 7 | updated: Date; 8 | } 9 | -------------------------------------------------------------------------------- /client/src/app/details/details.component.html: -------------------------------------------------------------------------------- 1 |
2 |
4 | 5 |
6 | 7 | 8 |
9 | {{post.postTitle}} 10 |

By: {{post.postAuthor}}, {{post.updated | date: 'dd MMM yyyy'}}

11 | {{post.postDesc}} 12 |
13 | {{post.postTitle}} 14 | 15 | 16 | 17 | 18 | 19 |
20 |
21 | -------------------------------------------------------------------------------- /client/src/app/details/details.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/didinj/mean-stack-angular-8-blog-cms/bc74491deaef105a1534fc300ba0869d180c5b48/client/src/app/details/details.component.scss -------------------------------------------------------------------------------- /client/src/app/details/details.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { DetailsComponent } from './details.component'; 4 | 5 | describe('DetailsComponent', () => { 6 | let component: DetailsComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ DetailsComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(DetailsComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /client/src/app/details/details.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { ActivatedRoute, Router } from '@angular/router'; 3 | import { Post } from '../post/post'; 4 | import { HomeService } from '../home.service'; 5 | 6 | @Component({ 7 | selector: 'app-details', 8 | templateUrl: './details.component.html', 9 | styleUrls: ['./details.component.scss'] 10 | }) 11 | export class DetailsComponent implements OnInit { 12 | 13 | post: Post = { 14 | category: '', 15 | id: '', 16 | postTitle: '', 17 | postAuthor: '', 18 | postDesc: '', 19 | postContent: '', 20 | postReference: '', 21 | postImgUrl: '', 22 | created: null, 23 | updated: null 24 | }; 25 | isLoadingResults = true; 26 | 27 | constructor(private route: ActivatedRoute, private api: HomeService, private router: Router) { } 28 | 29 | ngOnInit() { 30 | this.getPostDetails(this.route.snapshot.params.id); 31 | } 32 | 33 | getPostDetails(id: any) { 34 | this.api.getPost(id) 35 | .subscribe((data: any) => { 36 | this.post = data; 37 | console.log(this.post); 38 | this.isLoadingResults = false; 39 | }); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /client/src/app/home.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | 3 | import { HomeService } from './home.service'; 4 | 5 | describe('HomeService', () => { 6 | beforeEach(() => TestBed.configureTestingModule({})); 7 | 8 | it('should be created', () => { 9 | const service: HomeService = TestBed.get(HomeService); 10 | expect(service).toBeTruthy(); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /client/src/app/home.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient } from '@angular/common/http'; 3 | import { Observable, of } from 'rxjs'; 4 | import { catchError, tap } from 'rxjs/operators'; 5 | import { Category } from './category/category'; 6 | import { Post } from './post/post'; 7 | 8 | const apiUrl = 'http://localhost:3000/api/public/'; 9 | 10 | @Injectable({ 11 | providedIn: 'root' 12 | }) 13 | export class HomeService { 14 | 15 | constructor(private http: HttpClient) { } 16 | 17 | getCategories(): Observable { 18 | return this.http.get(apiUrl + 'category') 19 | .pipe( 20 | tap(_ => this.log('fetched Categories')), 21 | catchError(this.handleError('getCategories', [])) 22 | ); 23 | } 24 | 25 | getPosts(): Observable { 26 | return this.http.get(apiUrl + 'post') 27 | .pipe( 28 | tap(_ => this.log('fetched Posts')), 29 | catchError(this.handleError('getPosts', [])) 30 | ); 31 | } 32 | 33 | getPostsByCategory(id: any): Observable { 34 | return this.http.get(apiUrl + 'bycategory/' + id) 35 | .pipe( 36 | tap(_ => this.log('fetched Posts')), 37 | catchError(this.handleError('getPosts', [])) 38 | ); 39 | } 40 | 41 | getPost(id: any): Observable { 42 | return this.http.get(apiUrl + 'post/' + id).pipe( 43 | tap(_ => console.log(`fetched post by id=${id}`)), 44 | catchError(this.handleError(`getPost id=${id}`)) 45 | ); 46 | } 47 | 48 | private handleError(operation = 'operation', result?: T) { 49 | return (error: any): Observable => { 50 | 51 | console.error(error); // log to console instead 52 | this.log(`${operation} failed: ${error.message}`); 53 | 54 | return of(result as T); 55 | }; 56 | } 57 | 58 | private log(message: string) { 59 | console.log(message); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /client/src/app/home/home.component.html: -------------------------------------------------------------------------------- 1 |
2 |
4 | 5 |
6 | 7 | 8 | 9 | 10 |
11 | {{post.postTitle}} 12 | {{post.updated}} 13 |
14 | {{post.postTitle}} 15 | 16 | {{post.postDesc}} 17 | 18 |
19 |
20 |
21 |
22 | -------------------------------------------------------------------------------- /client/src/app/home/home.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/didinj/mean-stack-angular-8-blog-cms/bc74491deaef105a1534fc300ba0869d180c5b48/client/src/app/home/home.component.scss -------------------------------------------------------------------------------- /client/src/app/home/home.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { HomeComponent } from './home.component'; 4 | 5 | describe('HomeComponent', () => { 6 | let component: HomeComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ HomeComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(HomeComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /client/src/app/home/home.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Post } from '../post/post'; 3 | import { HomeService } from '../home.service'; 4 | 5 | @Component({ 6 | selector: 'app-home', 7 | templateUrl: './home.component.html', 8 | styleUrls: ['./home.component.scss'] 9 | }) 10 | export class HomeComponent implements OnInit { 11 | 12 | posts: Post[] = []; 13 | isLoadingResults = true; 14 | 15 | constructor(private api: HomeService) { } 16 | 17 | ngOnInit() { 18 | this.api.getPosts() 19 | .subscribe((res: any) => { 20 | this.posts = res; 21 | console.log(this.posts); 22 | this.isLoadingResults = false; 23 | }, err => { 24 | console.log(err); 25 | this.isLoadingResults = false; 26 | }); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /client/src/app/interceptors/token.interceptor.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { 3 | HttpRequest, 4 | HttpHandler, 5 | HttpEvent, 6 | HttpInterceptor, 7 | HttpResponse, 8 | HttpErrorResponse 9 | } from '@angular/common/http'; 10 | import { Observable, throwError } from 'rxjs'; 11 | import { map, catchError } from 'rxjs/operators'; 12 | import { Router } from '@angular/router'; 13 | 14 | @Injectable() 15 | export class TokenInterceptor implements HttpInterceptor { 16 | 17 | constructor(private router: Router) {} 18 | 19 | intercept(request: HttpRequest, next: HttpHandler): Observable> { 20 | 21 | const token = localStorage.getItem('token'); 22 | if (token) { 23 | request = request.clone({ 24 | setHeaders: { 25 | Authorization: token 26 | } 27 | }); 28 | } 29 | if (!request.headers.has('Content-Type')) { 30 | request = request.clone({ 31 | setHeaders: { 32 | 'content-type': 'application/json' 33 | } 34 | }); 35 | } 36 | request = request.clone({ 37 | headers: request.headers.set('Accept', 'application/json') 38 | }); 39 | return next.handle(request).pipe( 40 | map((event: HttpEvent) => { 41 | if (event instanceof HttpResponse) { 42 | console.log('event--->>>', event); 43 | } 44 | return event; 45 | }), 46 | catchError((error: HttpErrorResponse) => { 47 | console.log(error); 48 | if (error.status === 401) { 49 | this.router.navigate(['login']); 50 | } 51 | if (error.status === 400) { 52 | alert(error.error); 53 | } 54 | return throwError(error); 55 | })); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /client/src/app/post.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | 3 | import { PostService } from './post.service'; 4 | 5 | describe('PostService', () => { 6 | beforeEach(() => TestBed.configureTestingModule({})); 7 | 8 | it('should be created', () => { 9 | const service: PostService = TestBed.get(PostService); 10 | expect(service).toBeTruthy(); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /client/src/app/post.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient } from '@angular/common/http'; 3 | import { Observable, of } from 'rxjs'; 4 | import { catchError, tap } from 'rxjs/operators'; 5 | import { Post } from './post/post'; 6 | 7 | const apiUrl = 'http://localhost:3000/api/post/'; 8 | 9 | @Injectable({ 10 | providedIn: 'root' 11 | }) 12 | export class PostService { 13 | 14 | constructor(private http: HttpClient) { } 15 | 16 | getPosts(): Observable { 17 | return this.http.get(apiUrl) 18 | .pipe( 19 | tap(_ => this.log('fetched Posts')), 20 | catchError(this.handleError('getPosts', [])) 21 | ); 22 | } 23 | 24 | getPost(id: any): Observable { 25 | const url = `${apiUrl}/${id}`; 26 | return this.http.get(url).pipe( 27 | tap(_ => console.log(`fetched post by id=${id}`)), 28 | catchError(this.handleError(`getPost id=${id}`)) 29 | ); 30 | } 31 | 32 | addPost(post: Post): Observable { 33 | return this.http.post(apiUrl, post).pipe( 34 | tap((prod: Post) => console.log(`added post w/ id=${post.id}`)), 35 | catchError(this.handleError('addPost')) 36 | ); 37 | } 38 | 39 | updatePost(id: any, post: Post): Observable { 40 | const url = `${apiUrl}/${id}`; 41 | return this.http.put(url, post).pipe( 42 | tap(_ => console.log(`updated post id=${id}`)), 43 | catchError(this.handleError('updatePost')) 44 | ); 45 | } 46 | 47 | deletePost(id: any): Observable { 48 | const url = `${apiUrl}/${id}`; 49 | return this.http.delete(url).pipe( 50 | tap(_ => console.log(`deleted post id=${id}`)), 51 | catchError(this.handleError('deletePost')) 52 | ); 53 | } 54 | 55 | private handleError(operation = 'operation', result?: T) { 56 | return (error: any): Observable => { 57 | 58 | console.error(error); // log to console instead 59 | this.log(`${operation} failed: ${error.message}`); 60 | 61 | return of(result as T); 62 | }; 63 | } 64 | 65 | private log(message: string) { 66 | console.log(message); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /client/src/app/post/post-add/post-add.component.html: -------------------------------------------------------------------------------- 1 |
2 |
4 | 5 |
6 |
7 | list 8 |
9 | 10 |
11 | 12 | 13 | 14 | {{cat.catName}} 15 | 16 | 17 | 18 | Please select Category 19 | 20 | 21 | 22 | 24 | 25 | Please enter Post Title 26 | 27 | 28 | 29 | 31 | 32 | Please enter Post Author 33 | 34 | 35 | 36 | 38 | 39 | Please enter Post Description 40 | 41 | 42 | 43 | 44 | 45 | Please enter Post Content 46 | 47 | 48 |
49 | 50 | 52 | 53 | Please enter Post Ref 54 | 55 | 56 | 57 | 59 | 60 | Please enter Post Image URL 61 | 62 | 63 | 64 |
65 |
66 |
67 |
68 | -------------------------------------------------------------------------------- /client/src/app/post/post-add/post-add.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/didinj/mean-stack-angular-8-blog-cms/bc74491deaef105a1534fc300ba0869d180c5b48/client/src/app/post/post-add/post-add.component.scss -------------------------------------------------------------------------------- /client/src/app/post/post-add/post-add.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { PostAddComponent } from './post-add.component'; 4 | 5 | describe('PostAddComponent', () => { 6 | let component: PostAddComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ PostAddComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(PostAddComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /client/src/app/post/post-add/post-add.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Router } from '@angular/router'; 3 | import { PostService } from '../../post.service'; 4 | import { FormControl, FormGroupDirective, FormBuilder, FormGroup, NgForm, Validators } from '@angular/forms'; 5 | import { ErrorStateMatcher } from '@angular/material/core'; 6 | import { CategoryService } from '../../category.service'; 7 | import { Category } from './../../category/category'; 8 | 9 | /** Error when invalid control is dirty, touched, or submitted. */ 10 | export class MyErrorStateMatcher implements ErrorStateMatcher { 11 | isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean { 12 | const isSubmitted = form && form.submitted; 13 | return !!(control && control.invalid && (control.dirty || control.touched || isSubmitted)); 14 | } 15 | } 16 | 17 | @Component({ 18 | selector: 'app-post-add', 19 | templateUrl: './post-add.component.html', 20 | styleUrls: ['./post-add.component.scss'] 21 | }) 22 | export class PostAddComponent implements OnInit { 23 | 24 | postForm: FormGroup; 25 | category = ''; 26 | postTitle = ''; 27 | postAuthor = ''; 28 | postDesc = ''; 29 | postContent = ''; 30 | postReference = ''; 31 | postImgUrl = ''; 32 | isLoadingResults = false; 33 | matcher = new MyErrorStateMatcher(); 34 | categories: Category[] = []; 35 | 36 | constructor( 37 | private router: Router, 38 | private api: PostService, 39 | private catApi: CategoryService, 40 | private formBuilder: FormBuilder) { } 41 | 42 | ngOnInit() { 43 | this.getCategories(); 44 | this.postForm = this.formBuilder.group({ 45 | category : [null, Validators.required], 46 | postTitle : [null, Validators.required], 47 | postAuthor : [null, Validators.required], 48 | postDesc : [null, Validators.required], 49 | postContent : [null, Validators.required], 50 | postReference : [null, Validators.required], 51 | postImgUrl : [null, Validators.required] 52 | }); 53 | } 54 | 55 | onFormSubmit() { 56 | this.isLoadingResults = true; 57 | this.api.addPost(this.postForm.value) 58 | .subscribe((res: any) => { 59 | const id = res._id; 60 | this.isLoadingResults = false; 61 | this.router.navigate(['/post/details', id]); 62 | }, (err: any) => { 63 | console.log(err); 64 | this.isLoadingResults = false; 65 | }); 66 | } 67 | 68 | getCategories() { 69 | this.catApi.getCategories() 70 | .subscribe((res: any) => { 71 | this.categories = res; 72 | console.log(this.categories); 73 | this.isLoadingResults = false; 74 | }, err => { 75 | console.log(err); 76 | this.isLoadingResults = false; 77 | }); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /client/src/app/post/post-details/post-details.component.html: -------------------------------------------------------------------------------- 1 |
2 |
4 | 5 |
6 |
7 | list 8 |
9 | 10 | 11 |

{{post.postTitle}}

12 |

Created by: {{post.postAuthor}}, {{post.created | date}}, updated: {{post.updated | date}}

13 | {{post.postDesc}} 14 |
15 | {{post.postTitle}} 16 | 17 |
18 |
Post Content:
19 |
20 |
Reference:
21 |
{{post.postReference}}
22 |
23 |
24 | 25 | edit 26 | delete 27 | 28 |
29 |
30 | -------------------------------------------------------------------------------- /client/src/app/post/post-details/post-details.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/didinj/mean-stack-angular-8-blog-cms/bc74491deaef105a1534fc300ba0869d180c5b48/client/src/app/post/post-details/post-details.component.scss -------------------------------------------------------------------------------- /client/src/app/post/post-details/post-details.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { PostDetailsComponent } from './post-details.component'; 4 | 5 | describe('PostDetailsComponent', () => { 6 | let component: PostDetailsComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ PostDetailsComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(PostDetailsComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /client/src/app/post/post-details/post-details.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { ActivatedRoute, Router } from '@angular/router'; 3 | import { PostService } from './../../post.service'; 4 | import { Post } from '../post'; 5 | 6 | @Component({ 7 | selector: 'app-post-details', 8 | templateUrl: './post-details.component.html', 9 | styleUrls: ['./post-details.component.scss'] 10 | }) 11 | export class PostDetailsComponent implements OnInit { 12 | 13 | post: Post = { 14 | category: '', 15 | id: '', 16 | postTitle: '', 17 | postAuthor: '', 18 | postDesc: '', 19 | postContent: '', 20 | postReference: '', 21 | postImgUrl: '', 22 | created: null, 23 | updated: null 24 | }; 25 | isLoadingResults = true; 26 | 27 | constructor(private route: ActivatedRoute, private api: PostService, private router: Router) { } 28 | 29 | ngOnInit() { 30 | this.getPostDetails(this.route.snapshot.params.id); 31 | } 32 | 33 | getPostDetails(id: any) { 34 | this.api.getPost(id) 35 | .subscribe((data: any) => { 36 | this.post = data; 37 | this.post.id = data._id; 38 | console.log(this.post); 39 | this.isLoadingResults = false; 40 | }); 41 | } 42 | 43 | deletePost(id: any) { 44 | this.isLoadingResults = true; 45 | this.api.deletePost(id) 46 | .subscribe(res => { 47 | this.isLoadingResults = false; 48 | this.router.navigate(['/post']); 49 | }, (err) => { 50 | console.log(err); 51 | this.isLoadingResults = false; 52 | } 53 | ); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /client/src/app/post/post-edit/post-edit.component.html: -------------------------------------------------------------------------------- 1 |
2 |
4 | 5 |
6 |
7 | list 8 |
9 | 10 |
11 | 12 | 13 | 14 | {{cat.catName}} 15 | 16 | 17 | 18 | Please select Category 19 | 20 | 21 | 22 | 24 | 25 | Please enter Post Title 26 | 27 | 28 | 29 | 31 | 32 | Please enter Post Author 33 | 34 | 35 | 36 | 38 | 39 | Please enter Post Description 40 | 41 | 42 | 43 | 44 | 45 | Please enter Post Content 46 | 47 | 48 |
49 | 50 | 52 | 53 | Please enter Post Ref 54 | 55 | 56 | 57 | 59 | 60 | Please enter Post Image URL 61 | 62 | 63 | 64 |
65 |
66 |
67 |
68 | -------------------------------------------------------------------------------- /client/src/app/post/post-edit/post-edit.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/didinj/mean-stack-angular-8-blog-cms/bc74491deaef105a1534fc300ba0869d180c5b48/client/src/app/post/post-edit/post-edit.component.scss -------------------------------------------------------------------------------- /client/src/app/post/post-edit/post-edit.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { PostEditComponent } from './post-edit.component'; 4 | 5 | describe('PostEditComponent', () => { 6 | let component: PostEditComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ PostEditComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(PostEditComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /client/src/app/post/post-edit/post-edit.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Router, ActivatedRoute } from '@angular/router'; 3 | import { PostService } from '../../post.service'; 4 | import { FormControl, FormGroupDirective, FormBuilder, FormGroup, NgForm, Validators } from '@angular/forms'; 5 | import { ErrorStateMatcher } from '@angular/material/core'; 6 | import { CategoryService } from '../../category.service'; 7 | import { Category } from './../../category/category'; 8 | 9 | /** Error when invalid control is dirty, touched, or submitted. */ 10 | export class MyErrorStateMatcher implements ErrorStateMatcher { 11 | isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean { 12 | const isSubmitted = form && form.submitted; 13 | return !!(control && control.invalid && (control.dirty || control.touched || isSubmitted)); 14 | } 15 | } 16 | 17 | @Component({ 18 | selector: 'app-post-edit', 19 | templateUrl: './post-edit.component.html', 20 | styleUrls: ['./post-edit.component.scss'] 21 | }) 22 | export class PostEditComponent implements OnInit { 23 | 24 | postForm: FormGroup; 25 | category = ''; 26 | id = ''; 27 | postTitle = ''; 28 | postAuthor = ''; 29 | postDesc = ''; 30 | postContent = ''; 31 | postReference = ''; 32 | postImgUrl = ''; 33 | updated: Date = null; 34 | isLoadingResults = false; 35 | matcher = new MyErrorStateMatcher(); 36 | categories: Category[] = []; 37 | 38 | constructor( 39 | private router: Router, 40 | private route: ActivatedRoute, 41 | private api: PostService, 42 | private catApi: CategoryService, 43 | private formBuilder: FormBuilder) { } 44 | 45 | ngOnInit() { 46 | this.getCategories(); 47 | this.getPost(this.route.snapshot.params.id); 48 | this.postForm = this.formBuilder.group({ 49 | category : [null, Validators.required], 50 | postTitle : [null, Validators.required], 51 | postAuthor : [null, Validators.required], 52 | postDesc : [null, Validators.required], 53 | postContent : [null, Validators.required], 54 | postReference : [null, Validators.required], 55 | postImgUrl : [null, Validators.required] 56 | }); 57 | } 58 | 59 | getPost(id: any) { 60 | this.api.getPost(id).subscribe((data: any) => { 61 | this.id = data._id; 62 | this.postForm.setValue({ 63 | category: data.category, 64 | postTitle: data.postTitle, 65 | postAuthor: data.postAuthor, 66 | postDesc: data.postDesc, 67 | postContent: data.postContent, 68 | postReference: data.postReference, 69 | postImgUrl: data.postImgUrl 70 | }); 71 | }); 72 | } 73 | 74 | getCategories() { 75 | this.catApi.getCategories() 76 | .subscribe((res: any) => { 77 | this.categories = res; 78 | console.log(this.categories); 79 | this.isLoadingResults = false; 80 | }, err => { 81 | console.log(err); 82 | this.isLoadingResults = false; 83 | }); 84 | } 85 | 86 | onFormSubmit() { 87 | this.isLoadingResults = true; 88 | this.api.updatePost(this.id, this.postForm.value) 89 | .subscribe((res: any) => { 90 | const id = res._id; 91 | this.isLoadingResults = false; 92 | this.router.navigate(['/post/details', id]); 93 | }, (err: any) => { 94 | console.log(err); 95 | this.isLoadingResults = false; 96 | } 97 | ); 98 | } 99 | 100 | postDetails() { 101 | this.router.navigate(['/post/details', this.id]); 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /client/src/app/post/post.component.html: -------------------------------------------------------------------------------- 1 |
2 |
4 | 5 |
6 |
7 | add 8 |
9 |
10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
Post Title{{row.postTitle}}Post Description{{row.postDesc}}
28 |
29 |
30 | -------------------------------------------------------------------------------- /client/src/app/post/post.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/didinj/mean-stack-angular-8-blog-cms/bc74491deaef105a1534fc300ba0869d180c5b48/client/src/app/post/post.component.scss -------------------------------------------------------------------------------- /client/src/app/post/post.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { PostComponent } from './post.component'; 4 | 5 | describe('PostComponent', () => { 6 | let component: PostComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ PostComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(PostComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /client/src/app/post/post.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { PostService } from '../post.service'; 3 | import { Post } from './post'; 4 | 5 | @Component({ 6 | selector: 'app-post', 7 | templateUrl: './post.component.html', 8 | styleUrls: ['./post.component.scss'] 9 | }) 10 | export class PostComponent implements OnInit { 11 | 12 | displayedColumns: string[] = ['postTitle', 'postDesc']; 13 | data: Post[] = []; 14 | isLoadingResults = true; 15 | 16 | constructor(private api: PostService) { } 17 | 18 | ngOnInit() { 19 | this.api.getPosts() 20 | .subscribe((res: any) => { 21 | this.data = res; 22 | console.log(this.data); 23 | this.isLoadingResults = false; 24 | }, err => { 25 | console.log(err); 26 | this.isLoadingResults = false; 27 | }); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /client/src/app/post/post.ts: -------------------------------------------------------------------------------- 1 | export class Post { 2 | category: string; 3 | id: string; 4 | postTitle: string; 5 | postAuthor: string; 6 | postDesc: string; 7 | postContent: string; 8 | postReference: string; 9 | postImgUrl: string; 10 | created: Date; 11 | updated: Date; 12 | } 13 | -------------------------------------------------------------------------------- /client/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/didinj/mean-stack-angular-8-blog-cms/bc74491deaef105a1534fc300ba0869d180c5b48/client/src/assets/.gitkeep -------------------------------------------------------------------------------- /client/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /client/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /client/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/didinj/mean-stack-angular-8-blog-cms/bc74491deaef105a1534fc300ba0869d180c5b48/client/src/favicon.ico -------------------------------------------------------------------------------- /client/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Client 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /client/src/main.ts: -------------------------------------------------------------------------------- 1 | import 'hammerjs'; 2 | import { enableProdMode } from '@angular/core'; 3 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 4 | 5 | import { AppModule } from './app/app.module'; 6 | import { environment } from './environments/environment'; 7 | 8 | if (environment.production) { 9 | enableProdMode(); 10 | } 11 | 12 | platformBrowserDynamic().bootstrapModule(AppModule) 13 | .catch(err => console.error(err)); 14 | -------------------------------------------------------------------------------- /client/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags.ts'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js/dist/zone'; // Included with Angular CLI. 59 | 60 | 61 | /*************************************************************************************************** 62 | * APPLICATION IMPORTS 63 | */ 64 | -------------------------------------------------------------------------------- /client/src/styles.scss: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | 3 | html, body { height: 100%; } 4 | body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; } 5 | 6 | /* Structure */ 7 | .example-container { 8 | position: relative; 9 | padding: 5px; 10 | } 11 | 12 | .example-table-container { 13 | position: relative; 14 | max-height: 400px; 15 | overflow: auto; 16 | } 17 | 18 | table { 19 | width: 100%; 20 | } 21 | 22 | .example-loading-shade { 23 | position: absolute; 24 | top: 0; 25 | left: 0; 26 | bottom: 56px; 27 | right: 0; 28 | background: rgba(0, 0, 0, 0.15); 29 | z-index: 1; 30 | display: flex; 31 | align-items: center; 32 | justify-content: center; 33 | } 34 | 35 | .example-rate-limit-reached { 36 | color: #980000; 37 | max-width: 360px; 38 | text-align: center; 39 | } 40 | 41 | /* Column Widths */ 42 | .mat-column-number, 43 | .mat-column-state { 44 | max-width: 64px; 45 | } 46 | 47 | .mat-column-created { 48 | max-width: 124px; 49 | } 50 | 51 | .mat-flat-button { 52 | margin: 5px; 53 | } 54 | 55 | .example-container { 56 | position: relative; 57 | padding: 5px; 58 | } 59 | 60 | .example-form { 61 | min-width: 150px; 62 | max-width: 500px; 63 | width: 100%; 64 | } 65 | 66 | .example-full-width { 67 | width: 100%; 68 | } 69 | 70 | .example-full-width:nth-last-child(0) { 71 | margin-bottom: 10px; 72 | } 73 | 74 | .button-row { 75 | margin: 10px 0; 76 | } 77 | 78 | .mat-flat-button { 79 | margin: 5px; 80 | } 81 | -------------------------------------------------------------------------------- /client/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /client/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [] 6 | }, 7 | "files": [ 8 | "src/main.ts", 9 | "src/polyfills.ts" 10 | ], 11 | "include": [ 12 | "src/**/*.ts" 13 | ], 14 | "exclude": [ 15 | "src/test.ts", 16 | "src/**/*.spec.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /client/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "experimentalDecorators": true, 10 | "module": "esnext", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "typeRoots": [ 15 | "node_modules/@types" 16 | ], 17 | "lib": [ 18 | "es2018", 19 | "dom" 20 | ] 21 | }, 22 | "angularCompilerOptions": { 23 | "fullTemplateTypeCheck": true, 24 | "strictInjectionParameters": true 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /client/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /client/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "array-type": false, 5 | "arrow-parens": false, 6 | "deprecation": { 7 | "severity": "warning" 8 | }, 9 | "component-class-suffix": true, 10 | "contextual-lifecycle": true, 11 | "directive-class-suffix": true, 12 | "directive-selector": [ 13 | true, 14 | "attribute", 15 | "app", 16 | "camelCase" 17 | ], 18 | "component-selector": [ 19 | true, 20 | "element", 21 | "app", 22 | "kebab-case" 23 | ], 24 | "import-blacklist": [ 25 | true, 26 | "rxjs/Rx" 27 | ], 28 | "interface-name": false, 29 | "max-classes-per-file": false, 30 | "max-line-length": [ 31 | true, 32 | 140 33 | ], 34 | "member-access": false, 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-consecutive-blank-lines": false, 47 | "no-console": [ 48 | true, 49 | "debug", 50 | "info", 51 | "time", 52 | "timeEnd", 53 | "trace" 54 | ], 55 | "no-empty": false, 56 | "no-inferrable-types": [ 57 | true, 58 | "ignore-params" 59 | ], 60 | "no-non-null-assertion": true, 61 | "no-redundant-jsdoc": true, 62 | "no-switch-case-fall-through": true, 63 | "no-use-before-declare": true, 64 | "no-var-requires": false, 65 | "object-literal-key-quotes": [ 66 | true, 67 | "as-needed" 68 | ], 69 | "object-literal-sort-keys": false, 70 | "ordered-imports": false, 71 | "quotemark": [ 72 | true, 73 | "single" 74 | ], 75 | "trailing-comma": false, 76 | "no-conflicting-lifecycle": true, 77 | "no-host-metadata-property": true, 78 | "no-input-rename": true, 79 | "no-inputs-metadata-property": true, 80 | "no-output-native": true, 81 | "no-output-on-prefix": true, 82 | "no-output-rename": true, 83 | "no-outputs-metadata-property": true, 84 | "template-banana-in-box": true, 85 | "template-no-negated-async": true, 86 | "use-lifecycle-interface": true, 87 | "use-pipe-transform-interface": true 88 | }, 89 | "rulesDirectory": [ 90 | "codelyzer" 91 | ] 92 | } -------------------------------------------------------------------------------- /config/passport.js: -------------------------------------------------------------------------------- 1 | var JwtStrategy = require('passport-jwt').Strategy, 2 | ExtractJwt = require('passport-jwt').ExtractJwt; 3 | 4 | // load up the user model 5 | var User = require('../models/user'); 6 | var settings = require('../config/settings'); // get settings file 7 | 8 | module.exports = function(passport) { 9 | var opts = {}; 10 | opts.jwtFromRequest = ExtractJwt.fromAuthHeaderWithScheme("jwt"); 11 | opts.secretOrKey = settings.secret; 12 | passport.use(new JwtStrategy(opts, function(jwt_payload, done) { 13 | User.findOne({id: jwt_payload.id}, function(err, user) { 14 | if (err) { 15 | return done(err, false); 16 | } 17 | if (user) { 18 | done(null, user); 19 | } else { 20 | done(null, false); 21 | } 22 | }); 23 | })); 24 | }; -------------------------------------------------------------------------------- /config/settings.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 'secret':'meansecure' 3 | }; -------------------------------------------------------------------------------- /models/Category.js: -------------------------------------------------------------------------------- 1 | var mongoose = require('mongoose'); 2 | 3 | var CategorySchema = new mongoose.Schema({ 4 | id: String, 5 | catName: String, 6 | catDesc: String, 7 | catImgUrl: String, 8 | catContent: String, 9 | updated: { type: Date, default: Date.now }, 10 | }); 11 | 12 | module.exports = mongoose.model('Category', CategorySchema); -------------------------------------------------------------------------------- /models/Post.js: -------------------------------------------------------------------------------- 1 | var mongoose = require('mongoose'), Schema = mongoose.Schema; 2 | 3 | var PostSchema = new mongoose.Schema({ 4 | category : { type: Schema.Types.ObjectId, ref: 'Category' }, 5 | id: String, 6 | postTitle: String, 7 | postAuthor: String, 8 | postDesc: String, 9 | postContent: String, 10 | postReference: String, 11 | postImgUrl: String, 12 | created: { type: Date }, 13 | updated: { type: Date, default: Date.now }, 14 | }); 15 | 16 | module.exports = mongoose.model('Post', PostSchema); -------------------------------------------------------------------------------- /models/User.js: -------------------------------------------------------------------------------- 1 | var mongoose = require('mongoose'); 2 | var Schema = mongoose.Schema; 3 | var bcrypt = require('bcrypt-nodejs'); 4 | 5 | var UserSchema = new Schema({ 6 | fullName: { 7 | type: String, 8 | required: true 9 | }, 10 | username: { 11 | type: String, 12 | unique: true, 13 | required: true 14 | }, 15 | password: { 16 | type: String, 17 | required: true 18 | } 19 | }); 20 | 21 | UserSchema.pre('save', function (next) { 22 | var user = this; 23 | if (this.isModified('password') || this.isNew) { 24 | bcrypt.genSalt(10, function (err, salt) { 25 | if (err) { 26 | return next(err); 27 | } 28 | bcrypt.hash(user.password, salt, null, function (err, hash) { 29 | if (err) { 30 | return next(err); 31 | } 32 | user.password = hash; 33 | next(); 34 | }); 35 | }); 36 | } else { 37 | return next(); 38 | } 39 | }); 40 | 41 | UserSchema.methods.comparePassword = function (passw, cb) { 42 | bcrypt.compare(passw, this.password, function (err, isMatch) { 43 | if (err) { 44 | return cb(err); 45 | } 46 | cb(null, isMatch); 47 | }); 48 | }; 49 | 50 | module.exports = mongoose.model('User', UserSchema); -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "blog-cms", 3 | "version": "0.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "@types/bson": { 8 | "version": "4.0.5", 9 | "resolved": "https://registry.npmjs.org/@types/bson/-/bson-4.0.5.tgz", 10 | "integrity": "sha512-vVLwMUqhYJSQ/WKcE60eFqcyuWse5fGH+NMAXHuKrUAPoryq3ATxk5o4bgYNtg5aOM4APVg7Hnb3ASqUYG0PKg==", 11 | "requires": { 12 | "@types/node": "*" 13 | } 14 | }, 15 | "@types/mongodb": { 16 | "version": "3.6.20", 17 | "resolved": "https://registry.npmjs.org/@types/mongodb/-/mongodb-3.6.20.tgz", 18 | "integrity": "sha512-WcdpPJCakFzcWWD9juKoZbRtQxKIMYF/JIAM4JrNHrMcnJL6/a2NWjXxW7fo9hxboxxkg+icff8d7+WIEvKgYQ==", 19 | "requires": { 20 | "@types/bson": "*", 21 | "@types/node": "*" 22 | } 23 | }, 24 | "@types/node": { 25 | "version": "18.11.13", 26 | "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.13.tgz", 27 | "integrity": "sha512-IASpMGVcWpUsx5xBOrxMj7Bl8lqfuTY7FKAnPmu5cHkfQVWF8GulWS1jbRqA934qZL35xh5xN/+Xe/i26Bod4w==" 28 | }, 29 | "accepts": { 30 | "version": "1.3.8", 31 | "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", 32 | "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", 33 | "requires": { 34 | "mime-types": "~2.1.34", 35 | "negotiator": "0.6.3" 36 | } 37 | }, 38 | "array-flatten": { 39 | "version": "1.1.1", 40 | "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", 41 | "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==" 42 | }, 43 | "basic-auth": { 44 | "version": "2.0.1", 45 | "resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz", 46 | "integrity": "sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==", 47 | "requires": { 48 | "safe-buffer": "5.1.2" 49 | } 50 | }, 51 | "bcrypt-nodejs": { 52 | "version": "0.0.3", 53 | "resolved": "https://registry.npmjs.org/bcrypt-nodejs/-/bcrypt-nodejs-0.0.3.tgz", 54 | "integrity": "sha1-xgkX8m3CNWYVZsaBBhwwPCsohCs=" 55 | }, 56 | "bl": { 57 | "version": "2.2.1", 58 | "resolved": "https://registry.npmjs.org/bl/-/bl-2.2.1.tgz", 59 | "integrity": "sha512-6Pesp1w0DEX1N550i/uGV/TqucVL4AM/pgThFSN/Qq9si1/DF9aIHs1BxD8V/QU0HoeHO6cQRTAuYnLPKq1e4g==", 60 | "requires": { 61 | "readable-stream": "^2.3.5", 62 | "safe-buffer": "^5.1.1" 63 | } 64 | }, 65 | "bluebird": { 66 | "version": "3.5.5", 67 | "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.5.tgz", 68 | "integrity": "sha512-5am6HnnfN+urzt4yfg7IgTbotDjIT/u8AJpEt0sIU9FtXfVeezXAPKswrG+xKUCOYAINpSdgZVDU6QFh+cuH3w==" 69 | }, 70 | "body-parser": { 71 | "version": "1.19.2", 72 | "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.2.tgz", 73 | "integrity": "sha512-SAAwOxgoCKMGs9uUAUFHygfLAyaniaoun6I8mFY9pRAJL9+Kec34aU+oIjDhTycub1jozEfEwx1W1IuOYxVSFw==", 74 | "requires": { 75 | "bytes": "3.1.2", 76 | "content-type": "~1.0.4", 77 | "debug": "2.6.9", 78 | "depd": "~1.1.2", 79 | "http-errors": "1.8.1", 80 | "iconv-lite": "0.4.24", 81 | "on-finished": "~2.3.0", 82 | "qs": "6.9.7", 83 | "raw-body": "2.4.3", 84 | "type-is": "~1.6.18" 85 | } 86 | }, 87 | "bson": { 88 | "version": "1.1.6", 89 | "resolved": "https://registry.npmjs.org/bson/-/bson-1.1.6.tgz", 90 | "integrity": "sha512-EvVNVeGo4tHxwi8L6bPj3y3itEvStdwvvlojVxxbyYfoaxJ6keLgrTuKdyfEAszFK+H3olzBuafE0yoh0D1gdg==" 91 | }, 92 | "buffer-equal-constant-time": { 93 | "version": "1.0.1", 94 | "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", 95 | "integrity": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk=" 96 | }, 97 | "bytes": { 98 | "version": "3.1.2", 99 | "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", 100 | "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==" 101 | }, 102 | "content-disposition": { 103 | "version": "0.5.4", 104 | "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", 105 | "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", 106 | "requires": { 107 | "safe-buffer": "5.2.1" 108 | }, 109 | "dependencies": { 110 | "safe-buffer": { 111 | "version": "5.2.1", 112 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", 113 | "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" 114 | } 115 | } 116 | }, 117 | "content-type": { 118 | "version": "1.0.4", 119 | "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", 120 | "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==" 121 | }, 122 | "cookie": { 123 | "version": "0.3.1", 124 | "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz", 125 | "integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=" 126 | }, 127 | "cookie-parser": { 128 | "version": "1.4.4", 129 | "resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.4.tgz", 130 | "integrity": "sha512-lo13tqF3JEtFO7FyA49CqbhaFkskRJ0u/UAiINgrIXeRCY41c88/zxtrECl8AKH3B0hj9q10+h3Kt8I7KlW4tw==", 131 | "requires": { 132 | "cookie": "0.3.1", 133 | "cookie-signature": "1.0.6" 134 | } 135 | }, 136 | "cookie-signature": { 137 | "version": "1.0.6", 138 | "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", 139 | "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" 140 | }, 141 | "core-util-is": { 142 | "version": "1.0.3", 143 | "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", 144 | "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" 145 | }, 146 | "cors": { 147 | "version": "2.8.5", 148 | "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", 149 | "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", 150 | "requires": { 151 | "object-assign": "^4", 152 | "vary": "^1" 153 | } 154 | }, 155 | "debug": { 156 | "version": "2.6.9", 157 | "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", 158 | "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", 159 | "requires": { 160 | "ms": "2.0.0" 161 | } 162 | }, 163 | "denque": { 164 | "version": "1.5.1", 165 | "resolved": "https://registry.npmjs.org/denque/-/denque-1.5.1.tgz", 166 | "integrity": "sha512-XwE+iZ4D6ZUB7mfYRMb5wByE8L74HCn30FBN7sWnXksWc1LO1bPDl67pBR9o/kC4z/xSNAwkMYcGgqDV3BE3Hw==" 167 | }, 168 | "depd": { 169 | "version": "1.1.2", 170 | "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", 171 | "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" 172 | }, 173 | "destroy": { 174 | "version": "1.0.4", 175 | "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", 176 | "integrity": "sha512-3NdhDuEXnfun/z7x9GOElY49LoqVHoGScmOKwmxhsS8N5Y+Z8KyPPDnaSzqWgYt/ji4mqwfTS34Htrk0zPIXVg==" 177 | }, 178 | "ecdsa-sig-formatter": { 179 | "version": "1.0.11", 180 | "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", 181 | "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==", 182 | "requires": { 183 | "safe-buffer": "^5.0.1" 184 | } 185 | }, 186 | "ee-first": { 187 | "version": "1.1.1", 188 | "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", 189 | "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" 190 | }, 191 | "encodeurl": { 192 | "version": "1.0.2", 193 | "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", 194 | "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==" 195 | }, 196 | "escape-html": { 197 | "version": "1.0.3", 198 | "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", 199 | "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==" 200 | }, 201 | "etag": { 202 | "version": "1.8.1", 203 | "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", 204 | "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==" 205 | }, 206 | "express": { 207 | "version": "4.17.3", 208 | "resolved": "https://registry.npmjs.org/express/-/express-4.17.3.tgz", 209 | "integrity": "sha512-yuSQpz5I+Ch7gFrPCk4/c+dIBKlQUxtgwqzph132bsT6qhuzss6I8cLJQz7B3rFblzd6wtcI0ZbGltH/C4LjUg==", 210 | "requires": { 211 | "accepts": "~1.3.8", 212 | "array-flatten": "1.1.1", 213 | "body-parser": "1.19.2", 214 | "content-disposition": "0.5.4", 215 | "content-type": "~1.0.4", 216 | "cookie": "0.4.2", 217 | "cookie-signature": "1.0.6", 218 | "debug": "2.6.9", 219 | "depd": "~1.1.2", 220 | "encodeurl": "~1.0.2", 221 | "escape-html": "~1.0.3", 222 | "etag": "~1.8.1", 223 | "finalhandler": "~1.1.2", 224 | "fresh": "0.5.2", 225 | "merge-descriptors": "1.0.1", 226 | "methods": "~1.1.2", 227 | "on-finished": "~2.3.0", 228 | "parseurl": "~1.3.3", 229 | "path-to-regexp": "0.1.7", 230 | "proxy-addr": "~2.0.7", 231 | "qs": "6.9.7", 232 | "range-parser": "~1.2.1", 233 | "safe-buffer": "5.2.1", 234 | "send": "0.17.2", 235 | "serve-static": "1.14.2", 236 | "setprototypeof": "1.2.0", 237 | "statuses": "~1.5.0", 238 | "type-is": "~1.6.18", 239 | "utils-merge": "1.0.1", 240 | "vary": "~1.1.2" 241 | }, 242 | "dependencies": { 243 | "cookie": { 244 | "version": "0.4.2", 245 | "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz", 246 | "integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==" 247 | }, 248 | "safe-buffer": { 249 | "version": "5.2.1", 250 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", 251 | "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" 252 | } 253 | } 254 | }, 255 | "finalhandler": { 256 | "version": "1.1.2", 257 | "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", 258 | "integrity": "sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==", 259 | "requires": { 260 | "debug": "2.6.9", 261 | "encodeurl": "~1.0.2", 262 | "escape-html": "~1.0.3", 263 | "on-finished": "~2.3.0", 264 | "parseurl": "~1.3.3", 265 | "statuses": "~1.5.0", 266 | "unpipe": "~1.0.0" 267 | } 268 | }, 269 | "forwarded": { 270 | "version": "0.2.0", 271 | "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", 272 | "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==" 273 | }, 274 | "fresh": { 275 | "version": "0.5.2", 276 | "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", 277 | "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==" 278 | }, 279 | "http-errors": { 280 | "version": "1.8.1", 281 | "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.1.tgz", 282 | "integrity": "sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g==", 283 | "requires": { 284 | "depd": "~1.1.2", 285 | "inherits": "2.0.4", 286 | "setprototypeof": "1.2.0", 287 | "statuses": ">= 1.5.0 < 2", 288 | "toidentifier": "1.0.1" 289 | } 290 | }, 291 | "iconv-lite": { 292 | "version": "0.4.24", 293 | "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", 294 | "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", 295 | "requires": { 296 | "safer-buffer": ">= 2.1.2 < 3" 297 | } 298 | }, 299 | "inherits": { 300 | "version": "2.0.4", 301 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", 302 | "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" 303 | }, 304 | "ipaddr.js": { 305 | "version": "1.9.1", 306 | "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", 307 | "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==" 308 | }, 309 | "isarray": { 310 | "version": "1.0.0", 311 | "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", 312 | "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==" 313 | }, 314 | "jsonwebtoken": { 315 | "version": "8.5.1", 316 | "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz", 317 | "integrity": "sha512-XjwVfRS6jTMsqYs0EsuJ4LGxXV14zQybNd4L2r0UvbVnSF9Af8x7p5MzbJ90Ioz/9TI41/hTCvznF/loiSzn8w==", 318 | "requires": { 319 | "jws": "^3.2.2", 320 | "lodash.includes": "^4.3.0", 321 | "lodash.isboolean": "^3.0.3", 322 | "lodash.isinteger": "^4.0.4", 323 | "lodash.isnumber": "^3.0.3", 324 | "lodash.isplainobject": "^4.0.6", 325 | "lodash.isstring": "^4.0.1", 326 | "lodash.once": "^4.0.0", 327 | "ms": "^2.1.1", 328 | "semver": "^5.6.0" 329 | }, 330 | "dependencies": { 331 | "ms": { 332 | "version": "2.1.2", 333 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", 334 | "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" 335 | } 336 | } 337 | }, 338 | "jwa": { 339 | "version": "1.4.1", 340 | "resolved": "https://registry.npmjs.org/jwa/-/jwa-1.4.1.tgz", 341 | "integrity": "sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA==", 342 | "requires": { 343 | "buffer-equal-constant-time": "1.0.1", 344 | "ecdsa-sig-formatter": "1.0.11", 345 | "safe-buffer": "^5.0.1" 346 | } 347 | }, 348 | "jws": { 349 | "version": "3.2.2", 350 | "resolved": "https://registry.npmjs.org/jws/-/jws-3.2.2.tgz", 351 | "integrity": "sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==", 352 | "requires": { 353 | "jwa": "^1.4.1", 354 | "safe-buffer": "^5.0.1" 355 | } 356 | }, 357 | "kareem": { 358 | "version": "2.3.2", 359 | "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.3.2.tgz", 360 | "integrity": "sha512-STHz9P7X2L4Kwn72fA4rGyqyXdmrMSdxqHx9IXon/FXluXieaFA6KJ2upcHAHxQPQ0LeM/OjLrhFxifHewOALQ==" 361 | }, 362 | "lodash.includes": { 363 | "version": "4.3.0", 364 | "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", 365 | "integrity": "sha1-YLuYqHy5I8aMoeUTJUgzFISfVT8=" 366 | }, 367 | "lodash.isboolean": { 368 | "version": "3.0.3", 369 | "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", 370 | "integrity": "sha1-bC4XHbKiV82WgC/UOwGyDV9YcPY=" 371 | }, 372 | "lodash.isinteger": { 373 | "version": "4.0.4", 374 | "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz", 375 | "integrity": "sha1-YZwK89A/iwTDH1iChAt3sRzWg0M=" 376 | }, 377 | "lodash.isnumber": { 378 | "version": "3.0.3", 379 | "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", 380 | "integrity": "sha1-POdoEMWSjQM1IwGsKHMX8RwLH/w=" 381 | }, 382 | "lodash.isplainobject": { 383 | "version": "4.0.6", 384 | "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", 385 | "integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs=" 386 | }, 387 | "lodash.isstring": { 388 | "version": "4.0.1", 389 | "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", 390 | "integrity": "sha1-1SfftUVuynzJu5XV2ur4i6VKVFE=" 391 | }, 392 | "lodash.once": { 393 | "version": "4.1.1", 394 | "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", 395 | "integrity": "sha1-DdOXEhPHxW34gJd9UEyI+0cal6w=" 396 | }, 397 | "media-typer": { 398 | "version": "0.3.0", 399 | "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", 400 | "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==" 401 | }, 402 | "memory-pager": { 403 | "version": "1.5.0", 404 | "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", 405 | "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==", 406 | "optional": true 407 | }, 408 | "merge-descriptors": { 409 | "version": "1.0.1", 410 | "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", 411 | "integrity": "sha512-cCi6g3/Zr1iqQi6ySbseM1Xvooa98N0w31jzUYrXPX2xqObmFGHJ0tQ5u74H3mVh7wLouTseZyYIq39g8cNp1w==" 412 | }, 413 | "methods": { 414 | "version": "1.1.2", 415 | "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", 416 | "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==" 417 | }, 418 | "mime": { 419 | "version": "1.6.0", 420 | "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", 421 | "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==" 422 | }, 423 | "mime-db": { 424 | "version": "1.52.0", 425 | "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", 426 | "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==" 427 | }, 428 | "mime-types": { 429 | "version": "2.1.35", 430 | "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", 431 | "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", 432 | "requires": { 433 | "mime-db": "1.52.0" 434 | } 435 | }, 436 | "mongodb": { 437 | "version": "3.7.3", 438 | "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.7.3.tgz", 439 | "integrity": "sha512-Psm+g3/wHXhjBEktkxXsFMZvd3nemI0r3IPsE0bU+4//PnvNWKkzhZcEsbPcYiWqe8XqXJJEg4Tgtr7Raw67Yw==", 440 | "requires": { 441 | "bl": "^2.2.1", 442 | "bson": "^1.1.4", 443 | "denque": "^1.4.1", 444 | "optional-require": "^1.1.8", 445 | "safe-buffer": "^5.1.2", 446 | "saslprep": "^1.0.0" 447 | }, 448 | "dependencies": { 449 | "optional-require": { 450 | "version": "1.1.8", 451 | "resolved": "https://registry.npmjs.org/optional-require/-/optional-require-1.1.8.tgz", 452 | "integrity": "sha512-jq83qaUb0wNg9Krv1c5OQ+58EK+vHde6aBPzLvPPqJm89UQWsvSuFy9X/OSNJnFeSOKo7btE0n8Nl2+nE+z5nA==", 453 | "requires": { 454 | "require-at": "^1.0.6" 455 | } 456 | } 457 | } 458 | }, 459 | "mongoose": { 460 | "version": "5.13.15", 461 | "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.13.15.tgz", 462 | "integrity": "sha512-cxp1Gbb8yUWkaEbajdhspSaKzAvsIvOtRlYD87GN/P2QEUhpd6bIvebi36T6M0tIVAMauNaK9SPA055N3PwF8Q==", 463 | "requires": { 464 | "@types/bson": "1.x || 4.0.x", 465 | "@types/mongodb": "^3.5.27", 466 | "bson": "^1.1.4", 467 | "kareem": "2.3.2", 468 | "mongodb": "3.7.3", 469 | "mongoose-legacy-pluralize": "1.0.2", 470 | "mpath": "0.8.4", 471 | "mquery": "3.2.5", 472 | "ms": "2.1.2", 473 | "optional-require": "1.0.x", 474 | "regexp-clone": "1.0.0", 475 | "safe-buffer": "5.2.1", 476 | "sift": "13.5.2", 477 | "sliced": "1.0.1" 478 | }, 479 | "dependencies": { 480 | "ms": { 481 | "version": "2.1.2", 482 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", 483 | "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" 484 | }, 485 | "safe-buffer": { 486 | "version": "5.2.1", 487 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", 488 | "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" 489 | } 490 | } 491 | }, 492 | "mongoose-legacy-pluralize": { 493 | "version": "1.0.2", 494 | "resolved": "https://registry.npmjs.org/mongoose-legacy-pluralize/-/mongoose-legacy-pluralize-1.0.2.tgz", 495 | "integrity": "sha512-Yo/7qQU4/EyIS8YDFSeenIvXxZN+ld7YdV9LqFVQJzTLye8unujAWPZ4NWKfFA+RNjh+wvTWKY9Z3E5XM6ZZiQ==" 496 | }, 497 | "morgan": { 498 | "version": "1.9.1", 499 | "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.9.1.tgz", 500 | "integrity": "sha512-HQStPIV4y3afTiCYVxirakhlCfGkI161c76kKFca7Fk1JusM//Qeo1ej2XaMniiNeaZklMVrh3vTtIzpzwbpmA==", 501 | "requires": { 502 | "basic-auth": "~2.0.0", 503 | "debug": "2.6.9", 504 | "depd": "~1.1.2", 505 | "on-finished": "~2.3.0", 506 | "on-headers": "~1.0.1" 507 | } 508 | }, 509 | "mpath": { 510 | "version": "0.8.4", 511 | "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.8.4.tgz", 512 | "integrity": "sha512-DTxNZomBcTWlrMW76jy1wvV37X/cNNxPW1y2Jzd4DZkAaC5ZGsm8bfGfNOthcDuRJujXLqiuS6o3Tpy0JEoh7g==" 513 | }, 514 | "mquery": { 515 | "version": "3.2.5", 516 | "resolved": "https://registry.npmjs.org/mquery/-/mquery-3.2.5.tgz", 517 | "integrity": "sha512-VjOKHHgU84wij7IUoZzFRU07IAxd5kWJaDmyUzQlbjHjyoeK5TNeeo8ZsFDtTYnSgpW6n/nMNIHvE3u8Lbrf4A==", 518 | "requires": { 519 | "bluebird": "3.5.1", 520 | "debug": "3.1.0", 521 | "regexp-clone": "^1.0.0", 522 | "safe-buffer": "5.1.2", 523 | "sliced": "1.0.1" 524 | }, 525 | "dependencies": { 526 | "bluebird": { 527 | "version": "3.5.1", 528 | "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz", 529 | "integrity": "sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA==" 530 | }, 531 | "debug": { 532 | "version": "3.1.0", 533 | "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", 534 | "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", 535 | "requires": { 536 | "ms": "2.0.0" 537 | } 538 | } 539 | } 540 | }, 541 | "ms": { 542 | "version": "2.0.0", 543 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", 544 | "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" 545 | }, 546 | "negotiator": { 547 | "version": "0.6.3", 548 | "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", 549 | "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==" 550 | }, 551 | "object-assign": { 552 | "version": "4.1.1", 553 | "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", 554 | "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" 555 | }, 556 | "on-finished": { 557 | "version": "2.3.0", 558 | "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", 559 | "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", 560 | "requires": { 561 | "ee-first": "1.1.1" 562 | } 563 | }, 564 | "on-headers": { 565 | "version": "1.0.2", 566 | "resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz", 567 | "integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==" 568 | }, 569 | "optional-require": { 570 | "version": "1.0.3", 571 | "resolved": "https://registry.npmjs.org/optional-require/-/optional-require-1.0.3.tgz", 572 | "integrity": "sha512-RV2Zp2MY2aeYK5G+B/Sps8lW5NHAzE5QClbFP15j+PWmP+T9PxlJXBOOLoSAdgwFvS4t0aMR4vpedMkbHfh0nA==" 573 | }, 574 | "parseurl": { 575 | "version": "1.3.3", 576 | "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", 577 | "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==" 578 | }, 579 | "passport": { 580 | "version": "0.6.0", 581 | "resolved": "https://registry.npmjs.org/passport/-/passport-0.6.0.tgz", 582 | "integrity": "sha512-0fe+p3ZnrWRW74fe8+SvCyf4a3Pb2/h7gFkQ8yTJpAO50gDzlfjZUZTO1k5Eg9kUct22OxHLqDZoKUWRHOh9ug==", 583 | "requires": { 584 | "passport-strategy": "1.x.x", 585 | "pause": "0.0.1", 586 | "utils-merge": "^1.0.1" 587 | } 588 | }, 589 | "passport-jwt": { 590 | "version": "4.0.0", 591 | "resolved": "https://registry.npmjs.org/passport-jwt/-/passport-jwt-4.0.0.tgz", 592 | "integrity": "sha512-BwC0n2GP/1hMVjR4QpnvqA61TxenUMlmfNjYNgK0ZAs0HK4SOQkHcSv4L328blNTLtHq7DbmvyNJiH+bn6C5Mg==", 593 | "requires": { 594 | "jsonwebtoken": "^8.2.0", 595 | "passport-strategy": "^1.0.0" 596 | } 597 | }, 598 | "passport-strategy": { 599 | "version": "1.0.0", 600 | "resolved": "https://registry.npmjs.org/passport-strategy/-/passport-strategy-1.0.0.tgz", 601 | "integrity": "sha1-tVOaqPwiWj0a0XlHbd8ja0QPUuQ=" 602 | }, 603 | "path-to-regexp": { 604 | "version": "0.1.7", 605 | "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", 606 | "integrity": "sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==" 607 | }, 608 | "pause": { 609 | "version": "0.0.1", 610 | "resolved": "https://registry.npmjs.org/pause/-/pause-0.0.1.tgz", 611 | "integrity": "sha512-KG8UEiEVkR3wGEb4m5yZkVCzigAD+cVEJck2CzYZO37ZGJfctvVptVO192MwrtPhzONn6go8ylnOdMhKqi4nfg==" 612 | }, 613 | "process-nextick-args": { 614 | "version": "2.0.1", 615 | "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", 616 | "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" 617 | }, 618 | "proxy-addr": { 619 | "version": "2.0.7", 620 | "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", 621 | "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", 622 | "requires": { 623 | "forwarded": "0.2.0", 624 | "ipaddr.js": "1.9.1" 625 | } 626 | }, 627 | "qs": { 628 | "version": "6.9.7", 629 | "resolved": "https://registry.npmjs.org/qs/-/qs-6.9.7.tgz", 630 | "integrity": "sha512-IhMFgUmuNpyRfxA90umL7ByLlgRXu6tIfKPpF5TmcfRLlLCckfP/g3IQmju6jjpu+Hh8rA+2p6A27ZSPOOHdKw==" 631 | }, 632 | "range-parser": { 633 | "version": "1.2.1", 634 | "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", 635 | "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==" 636 | }, 637 | "raw-body": { 638 | "version": "2.4.3", 639 | "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.3.tgz", 640 | "integrity": "sha512-UlTNLIcu0uzb4D2f4WltY6cVjLi+/jEN4lgEUj3E04tpMDpUlkBo/eSn6zou9hum2VMNpCCUone0O0WeJim07g==", 641 | "requires": { 642 | "bytes": "3.1.2", 643 | "http-errors": "1.8.1", 644 | "iconv-lite": "0.4.24", 645 | "unpipe": "1.0.0" 646 | } 647 | }, 648 | "readable-stream": { 649 | "version": "2.3.7", 650 | "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", 651 | "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", 652 | "requires": { 653 | "core-util-is": "~1.0.0", 654 | "inherits": "~2.0.3", 655 | "isarray": "~1.0.0", 656 | "process-nextick-args": "~2.0.0", 657 | "safe-buffer": "~5.1.1", 658 | "string_decoder": "~1.1.1", 659 | "util-deprecate": "~1.0.1" 660 | } 661 | }, 662 | "regexp-clone": { 663 | "version": "1.0.0", 664 | "resolved": "https://registry.npmjs.org/regexp-clone/-/regexp-clone-1.0.0.tgz", 665 | "integrity": "sha512-TuAasHQNamyyJ2hb97IuBEif4qBHGjPHBS64sZwytpLEqtBQ1gPJTnOaQ6qmpET16cK14kkjbazl6+p0RRv0yw==" 666 | }, 667 | "require-at": { 668 | "version": "1.0.6", 669 | "resolved": "https://registry.npmjs.org/require-at/-/require-at-1.0.6.tgz", 670 | "integrity": "sha512-7i1auJbMUrXEAZCOQ0VNJgmcT2VOKPRl2YGJwgpHpC9CE91Mv4/4UYIUm4chGJaI381ZDq1JUicFii64Hapd8g==" 671 | }, 672 | "safe-buffer": { 673 | "version": "5.1.2", 674 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", 675 | "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" 676 | }, 677 | "safer-buffer": { 678 | "version": "2.1.2", 679 | "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", 680 | "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" 681 | }, 682 | "saslprep": { 683 | "version": "1.0.3", 684 | "resolved": "https://registry.npmjs.org/saslprep/-/saslprep-1.0.3.tgz", 685 | "integrity": "sha512-/MY/PEMbk2SuY5sScONwhUDsV2p77Znkb/q3nSVstq/yQzYJOH/Azh29p9oJLsl3LnQwSvZDKagDGBsBwSooag==", 686 | "optional": true, 687 | "requires": { 688 | "sparse-bitfield": "^3.0.3" 689 | } 690 | }, 691 | "semver": { 692 | "version": "5.7.1", 693 | "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", 694 | "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" 695 | }, 696 | "send": { 697 | "version": "0.17.2", 698 | "resolved": "https://registry.npmjs.org/send/-/send-0.17.2.tgz", 699 | "integrity": "sha512-UJYB6wFSJE3G00nEivR5rgWp8c2xXvJ3OPWPhmuteU0IKj8nKbG3DrjiOmLwpnHGYWAVwA69zmTm++YG0Hmwww==", 700 | "requires": { 701 | "debug": "2.6.9", 702 | "depd": "~1.1.2", 703 | "destroy": "~1.0.4", 704 | "encodeurl": "~1.0.2", 705 | "escape-html": "~1.0.3", 706 | "etag": "~1.8.1", 707 | "fresh": "0.5.2", 708 | "http-errors": "1.8.1", 709 | "mime": "1.6.0", 710 | "ms": "2.1.3", 711 | "on-finished": "~2.3.0", 712 | "range-parser": "~1.2.1", 713 | "statuses": "~1.5.0" 714 | }, 715 | "dependencies": { 716 | "ms": { 717 | "version": "2.1.3", 718 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", 719 | "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" 720 | } 721 | } 722 | }, 723 | "serve-static": { 724 | "version": "1.14.2", 725 | "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.14.2.tgz", 726 | "integrity": "sha512-+TMNA9AFxUEGuC0z2mevogSnn9MXKb4fa7ngeRMJaaGv8vTwnIEkKi+QGvPt33HSnf8pRS+WGM0EbMtCJLKMBQ==", 727 | "requires": { 728 | "encodeurl": "~1.0.2", 729 | "escape-html": "~1.0.3", 730 | "parseurl": "~1.3.3", 731 | "send": "0.17.2" 732 | } 733 | }, 734 | "setprototypeof": { 735 | "version": "1.2.0", 736 | "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", 737 | "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" 738 | }, 739 | "sift": { 740 | "version": "13.5.2", 741 | "resolved": "https://registry.npmjs.org/sift/-/sift-13.5.2.tgz", 742 | "integrity": "sha512-+gxdEOMA2J+AI+fVsCqeNn7Tgx3M9ZN9jdi95939l1IJ8cZsqS8sqpJyOkic2SJk+1+98Uwryt/gL6XDaV+UZA==" 743 | }, 744 | "sliced": { 745 | "version": "1.0.1", 746 | "resolved": "https://registry.npmjs.org/sliced/-/sliced-1.0.1.tgz", 747 | "integrity": "sha512-VZBmZP8WU3sMOZm1bdgTadsQbcscK0UM8oKxKVBs4XAhUo2Xxzm/OFMGBkPusxw9xL3Uy8LrzEqGqJhclsr0yA==" 748 | }, 749 | "sparse-bitfield": { 750 | "version": "3.0.3", 751 | "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", 752 | "integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==", 753 | "optional": true, 754 | "requires": { 755 | "memory-pager": "^1.0.2" 756 | } 757 | }, 758 | "statuses": { 759 | "version": "1.5.0", 760 | "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", 761 | "integrity": "sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==" 762 | }, 763 | "string_decoder": { 764 | "version": "1.1.1", 765 | "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", 766 | "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", 767 | "requires": { 768 | "safe-buffer": "~5.1.0" 769 | } 770 | }, 771 | "toidentifier": { 772 | "version": "1.0.1", 773 | "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", 774 | "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==" 775 | }, 776 | "type-is": { 777 | "version": "1.6.18", 778 | "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", 779 | "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", 780 | "requires": { 781 | "media-typer": "0.3.0", 782 | "mime-types": "~2.1.24" 783 | } 784 | }, 785 | "unpipe": { 786 | "version": "1.0.0", 787 | "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", 788 | "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==" 789 | }, 790 | "util-deprecate": { 791 | "version": "1.0.2", 792 | "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", 793 | "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" 794 | }, 795 | "utils-merge": { 796 | "version": "1.0.1", 797 | "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", 798 | "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==" 799 | }, 800 | "vary": { 801 | "version": "1.1.2", 802 | "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", 803 | "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" 804 | } 805 | } 806 | } 807 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "blog-cms", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "start": "node ./bin/www" 7 | }, 8 | "dependencies": { 9 | "bcrypt-nodejs": "0.0.3", 10 | "bluebird": "^3.5.5", 11 | "cookie-parser": "~1.4.4", 12 | "cors": "^2.8.5", 13 | "debug": "~2.6.9", 14 | "express": "~4.17.3", 15 | "jsonwebtoken": "^8.5.1", 16 | "mongoose": "^5.13.15", 17 | "morgan": "^1.9.1", 18 | "passport": "^0.6.0", 19 | "passport-jwt": "^4.0.0" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Express 5 | 6 | 7 | 8 | 9 |

Express

10 |

Welcome to Express

11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /public/stylesheets/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding: 50px; 3 | font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; 4 | } 5 | 6 | a { 7 | color: #00B7FF; 8 | } 9 | -------------------------------------------------------------------------------- /routes/auth.js: -------------------------------------------------------------------------------- 1 | var passport = require('passport'); 2 | var config = require('../config/settings'); 3 | require('../config/passport')(passport); 4 | var express = require('express'); 5 | var jwt = require('jsonwebtoken'); 6 | var router = express.Router(); 7 | var User = require("../models/user"); 8 | 9 | router.post('/register', function(req, res) { 10 | if (!req.body.fullName || !req.body.username || !req.body.password) { 11 | res.json({success: false, msg: 'Please pass full name, username and password.'}); 12 | } else { 13 | var newUser = new User({ 14 | fullName: req.body.fullName, 15 | username: req.body.username, 16 | password: req.body.password 17 | }); 18 | // save the user 19 | newUser.save(function(err) { 20 | if (err) { 21 | return res.json({success: false, msg: 'Username already exists.'}); 22 | } 23 | res.json({success: true, msg: 'Successful created new user.'}); 24 | }); 25 | } 26 | }); 27 | 28 | router.post('/login', function(req, res) { 29 | User.findOne({ 30 | username: req.body.username 31 | }, function(err, user) { 32 | if (err) throw err; 33 | 34 | if (!user) { 35 | res.status(401).send({success: false, msg: 'Authentication failed. User not found.'}); 36 | } else { 37 | // check if password matches 38 | user.comparePassword(req.body.password, function (err, isMatch) { 39 | if (isMatch && !err) { 40 | // if user is found and password is right create a token 41 | var token = jwt.sign(user.toJSON(), config.secret); 42 | // return the information including token as JSON 43 | res.json({success: true, token: 'JWT ' + token}); 44 | } else { 45 | res.status(401).send({success: false, msg: 'Authentication failed. Wrong password.'}); 46 | } 47 | }); 48 | } 49 | }); 50 | }); 51 | 52 | router.post('/logout', passport.authenticate('jwt', { session: false}), function(req, res) { 53 | req.logout(); 54 | res.json({success: true}); 55 | }); 56 | 57 | module.exports = router; -------------------------------------------------------------------------------- /routes/category.js: -------------------------------------------------------------------------------- 1 | var passport = require('passport'); 2 | require('../config/passport')(passport); 3 | var express = require('express'); 4 | var router = express.Router(); 5 | var Category = require("../models/category"); 6 | 7 | router.get('/', passport.authenticate('jwt', { session: false}), function(req, res) { 8 | var token = getToken(req.headers); 9 | if (token) { 10 | Category.find(function (err, categories) { 11 | if (err) return next(err); 12 | res.json(categories); 13 | }); 14 | } else { 15 | return res.status(403).send({success: false, msg: 'Unauthorized.'}); 16 | } 17 | }); 18 | 19 | router.get('/:id', passport.authenticate('jwt', { session: false}), function(req, res, next) { 20 | var token = getToken(req.headers); 21 | if (token) { 22 | Category.findById(req.params.id, function (err, category) { 23 | if (err) return next(err); 24 | res.json(category); 25 | }); 26 | } else { 27 | return res.status(403).send({success: false, msg: 'Unauthorized.'}); 28 | } 29 | }); 30 | 31 | router.post('/', passport.authenticate('jwt', { session: false}), function(req, res, next) { 32 | var token = getToken(req.headers); 33 | if (token) { 34 | Category.create(req.body, function (err, category) { 35 | if (err) return next(err); 36 | res.json(category); 37 | }); 38 | } else { 39 | return res.status(403).send({success: false, msg: 'Unauthorized.'}); 40 | } 41 | }); 42 | 43 | router.put('/:id', passport.authenticate('jwt', { session: false}), function(req, res, next) { 44 | var token = getToken(req.headers); 45 | if (token) { 46 | Category.findByIdAndUpdate(req.params.id, req.body, function (err, category) { 47 | if (err) return next(err); 48 | res.json(category); 49 | }); 50 | } else { 51 | return res.status(403).send({success: false, msg: 'Unauthorized.'}); 52 | } 53 | }); 54 | 55 | router.delete('/:id', passport.authenticate('jwt', { session: false}), function(req, res, next) { 56 | var token = getToken(req.headers); 57 | if (token) { 58 | Category.findByIdAndRemove(req.params.id, req.body, function (err, category) { 59 | if (err) return next(err); 60 | res.json(category); 61 | }); 62 | } else { 63 | return res.status(403).send({success: false, msg: 'Unauthorized.'}); 64 | } 65 | }); 66 | 67 | getToken = function (headers) { 68 | if (headers && headers.authorization) { 69 | var parted = headers.authorization.split(' '); 70 | if (parted.length === 2) { 71 | return parted[1]; 72 | } else { 73 | return null; 74 | } 75 | } else { 76 | return null; 77 | } 78 | }; 79 | 80 | module.exports = router; -------------------------------------------------------------------------------- /routes/index.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var router = express.Router(); 3 | var Category = require("../models/category"); 4 | var Post = require("../models/post"); 5 | 6 | /* GET home page. */ 7 | router.get('/', function(req, res, next) { 8 | res.render('index', { title: 'Express' }); 9 | }); 10 | 11 | router.get('/category', function(req, res, next) { 12 | Category.find(function (err, categories) { 13 | if (err) return next(err); 14 | res.json(categories); 15 | }); 16 | }); 17 | 18 | router.get('/post', function(req, res, next) { 19 | Post.find(function (err, posts) { 20 | if (err) return next(err); 21 | res.json(posts); 22 | }); 23 | }); 24 | 25 | router.get('/bycategory/:id', function(req, res, next) { 26 | Post.find({category: req.params.id}, function (err, posts) { 27 | if (err) return next(err); 28 | res.json(posts); 29 | }); 30 | }); 31 | 32 | router.get('/post/:id', function(req, res, next) { 33 | Post.findById(req.params.id, function (err, post) { 34 | if (err) return next(err); 35 | res.json(post); 36 | }); 37 | }); 38 | 39 | module.exports = router; 40 | -------------------------------------------------------------------------------- /routes/post.js: -------------------------------------------------------------------------------- 1 | var passport = require('passport'); 2 | require('../config/passport')(passport); 3 | var express = require('express'); 4 | var router = express.Router(); 5 | var Post = require("../models/post"); 6 | 7 | router.get('/', passport.authenticate('jwt', { session: false}), function(req, res) { 8 | var token = getToken(req.headers); 9 | if (token) { 10 | Post.find(function (err, posts) { 11 | if (err) return next(err); 12 | res.json(posts); 13 | }); 14 | } else { 15 | return res.status(403).send({success: false, msg: 'Unauthorized.'}); 16 | } 17 | }); 18 | 19 | router.get('/:id', passport.authenticate('jwt', { session: false}), function(req, res, next) { 20 | var token = getToken(req.headers); 21 | if (token) { 22 | Post.findById(req.params.id, function (err, post) { 23 | if (err) return next(err); 24 | res.json(post); 25 | }); 26 | } else { 27 | return res.status(403).send({success: false, msg: 'Unauthorized.'}); 28 | } 29 | }); 30 | 31 | router.post('/', passport.authenticate('jwt', { session: false}), function(req, res, next) { 32 | var token = getToken(req.headers); 33 | if (token) { 34 | Post.create(req.body, function (err, post) { 35 | if (err) return next(err); 36 | res.json(post); 37 | }); 38 | } else { 39 | return res.status(403).send({success: false, msg: 'Unauthorized.'}); 40 | } 41 | }); 42 | 43 | router.put('/:id', passport.authenticate('jwt', { session: false}), function(req, res, next) { 44 | var token = getToken(req.headers); 45 | if (token) { 46 | Post.findByIdAndUpdate(req.params.id, req.body, function (err, post) { 47 | if (err) return next(err); 48 | res.json(post); 49 | }); 50 | } else { 51 | return res.status(403).send({success: false, msg: 'Unauthorized.'}); 52 | } 53 | }); 54 | 55 | router.delete('/:id', passport.authenticate('jwt', { session: false}), function(req, res, next) { 56 | var token = getToken(req.headers); 57 | if (token) { 58 | Post.findByIdAndRemove(req.params.id, req.body, function (err, post) { 59 | if (err) return next(err); 60 | res.json(post); 61 | }); 62 | } else { 63 | return res.status(403).send({success: false, msg: 'Unauthorized.'}); 64 | } 65 | }); 66 | 67 | getToken = function (headers) { 68 | if (headers && headers.authorization) { 69 | var parted = headers.authorization.split(' '); 70 | if (parted.length === 2) { 71 | return parted[1]; 72 | } else { 73 | return null; 74 | } 75 | } else { 76 | return null; 77 | } 78 | }; 79 | 80 | module.exports = router; -------------------------------------------------------------------------------- /routes/users.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var router = express.Router(); 3 | 4 | /* GET users listing. */ 5 | router.get('/', function(req, res, next) { 6 | res.send('respond with a resource'); 7 | }); 8 | 9 | module.exports = router; 10 | --------------------------------------------------------------------------------