Skip to content

Commit

Permalink
commit to deploy it to heroku
Browse files Browse the repository at this point in the history
  • Loading branch information
SaddamMohsen committed Apr 16, 2020
1 parent 700457f commit e8563ee
Show file tree
Hide file tree
Showing 24 changed files with 223 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
build
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
.env
Blogs.txt
tests
57 changes: 57 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"name": "vscode-jest-tests",
"request": "launch",
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
"args": [
"--runInBand"
],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true
},
{
"type": "node",
"request": "launch",
"name": "Launch via NPM",
"runtimeExecutable": "npm test",
"runtimeArgs": [
"run-script",
"debug"
],
"port": 9229,
"skipFiles": [
"<node_internals>/**"
]
},
{
"type": "node",
"name": "vscode-jest-tests",
"request": "launch",
"args": [
"--runInBand"
],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\index.js"
}
]
}
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node index.js
20 changes: 15 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,30 @@ const loginRouter= require('./controllers/login')
const path = require('path')
logger.info('connected to', config.MONGODB_URI)

//for testing purpose
if (process.env.NODE_ENV === 'test') {
logger.info('in test mode')
const testingRouter = require('./controllers/testingRouter')
app.use('/api/testing', testingRouter)
}
mongoose.connect(config.MONGODB_URI, { useNewUrlParser: true, useUnifiedTopology: true ,useFindAndModify: false})
.then(result => {
console.log('connected to ',config.MONGODB_URI)
logger.info('connected to MongoDB')
})
.catch((error) => {
logger.error('error connecting to MongoDB:', error.message)
})
app.use(express.static(path.join(__dirname, 'build')))

app.get('/ping', (req, res) => {
/*app.get('/ping', (req, res) => {
return res.send('pong')
})
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'build', 'index.html'))
})
/*app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});*/
})*/

app.use(cors())
app.use(bodyParser.json())
app.use(middleware.requestLogger)
Expand All @@ -39,4 +44,9 @@ app.use('/api/blogs', blogsRouter)
app.use('/api/users', usersRouter)
app.use(middleware.unknownEndpoint)
app.use(middleware.errorHandler)

app.get('/', (req, res)=> {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});

module.exports = app
15 changes: 15 additions & 0 deletions build/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"files": {
"main.css": "/static/css/main.466a9151.chunk.css",
"main.js": "/static/js/main.748aa352.chunk.js",
"main.js.map": "/static/js/main.748aa352.chunk.js.map",
"runtime~main.js": "/static/js/runtime~main.a8a9905a.js",
"runtime~main.js.map": "/static/js/runtime~main.a8a9905a.js.map",
"static/js/2.4c569fc1.chunk.js": "/static/js/2.4c569fc1.chunk.js",
"static/js/2.4c569fc1.chunk.js.map": "/static/js/2.4c569fc1.chunk.js.map",
"index.html": "/index.html",
"precache-manifest.47bb7ac401cdb8f0e7c6b184ab9c0fc7.js": "/precache-manifest.47bb7ac401cdb8f0e7c6b184ab9c0fc7.js",
"service-worker.js": "/service-worker.js",
"static/css/main.466a9151.chunk.css.map": "/static/css/main.466a9151.chunk.css.map"
}
}
7 changes: 7 additions & 0 deletions build/bootstrap.min.css

Large diffs are not rendered by default.

Binary file added build/favicon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions build/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><title>BLog List Application</title><link href="/static/css/main.466a9151.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(l){function e(e){for(var r,t,n=e[0],o=e[1],u=e[2],f=0,i=[];f<n.length;f++)t=n[f],p[t]&&i.push(p[t][0]),p[t]=0;for(r in o)Object.prototype.hasOwnProperty.call(o,r)&&(l[r]=o[r]);for(s&&s(e);i.length;)i.shift()();return c.push.apply(c,u||[]),a()}function a(){for(var e,r=0;r<c.length;r++){for(var t=c[r],n=!0,o=1;o<t.length;o++){var u=t[o];0!==p[u]&&(n=!1)}n&&(c.splice(r--,1),e=f(f.s=t[0]))}return e}var t={},p={1:0},c=[];function f(e){if(t[e])return t[e].exports;var r=t[e]={i:e,l:!1,exports:{}};return l[e].call(r.exports,r,r.exports,f),r.l=!0,r.exports}f.m=l,f.c=t,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(r,e){if(1&e&&(r=f(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var n in r)f.d(t,n,function(e){return r[e]}.bind(null,n));return t},f.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},f.p="/";var r=window.webpackJsonp=window.webpackJsonp||[],n=r.push.bind(r);r.push=e,r=r.slice();for(var o=0;o<r.length;o++)e(r[o]);var s=n;a()}([])</script><script src="/static/js/2.4c569fc1.chunk.js"></script><script src="/static/js/main.748aa352.chunk.js"></script></body></html>
15 changes: 15 additions & 0 deletions build/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
22 changes: 22 additions & 0 deletions build/precache-manifest.47bb7ac401cdb8f0e7c6b184ab9c0fc7.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
self.__precacheManifest = (self.__precacheManifest || []).concat([
{
"revision": "d293ab77f27a1f6246840209757127e1",
"url": "/index.html"
},
{
"revision": "784e381ba81823cf0970",
"url": "/static/css/main.466a9151.chunk.css"
},
{
"revision": "7906c12361e946928cf7",
"url": "/static/js/2.4c569fc1.chunk.js"
},
{
"revision": "784e381ba81823cf0970",
"url": "/static/js/main.748aa352.chunk.js"
},
{
"revision": "42ac5946195a7306e2a5",
"url": "/static/js/runtime~main.a8a9905a.js"
}
]);
39 changes: 39 additions & 0 deletions build/service-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Welcome to your Workbox-powered service worker!
*
* You'll need to register this file in your web app and you should
* disable HTTP caching for this file too.
* See https://goo.gl/nhQhGp
*
* The rest of the code is auto-generated. Please don't update this file
* directly; instead, make changes to your Workbox build configuration
* and re-run your build process.
* See https://goo.gl/2aRDsh
*/

importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");

importScripts(
"/precache-manifest.47bb7ac401cdb8f0e7c6b184ab9c0fc7.js"
);

self.addEventListener('message', (event) => {
if (event.data && event.data.type === 'SKIP_WAITING') {
self.skipWaiting();
}
});

workbox.core.clientsClaim();

/**
* The workboxSW.precacheAndRoute() method efficiently caches and responds to
* requests for URLs in the manifest.
* See https://goo.gl/S9QRab
*/
self.__precacheManifest = [].concat(self.__precacheManifest || []);
workbox.precaching.precacheAndRoute(self.__precacheManifest, {});

workbox.routing.registerNavigationRoute(workbox.precaching.getCacheKeyForURL("/index.html"), {

blacklist: [/^\/_/,/\/[^\/]+\.[^\/]+$/],
});
9 changes: 9 additions & 0 deletions build/static/css/main.466a9151.chunk.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build/static/css/main.466a9151.chunk.css.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions build/static/js/2.4c569fc1.chunk.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build/static/js/2.4c569fc1.chunk.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions build/static/js/main.748aa352.chunk.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build/static/js/main.748aa352.chunk.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions build/static/js/runtime~main.a8a9905a.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/static/js/runtime~main.a8a9905a.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions controllers/blogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ blogsRouter.post('/', async(request, response, next) => {
}

const user = await User.findById(decodedToken.id)
console.log('in blog post',user)
//console.log('in blog post',user)
const blogg = new Blog({
title: body.title,
author: body.author,
Expand Down Expand Up @@ -71,7 +71,7 @@ blogsRouter.put('/:id', async(req, resp, next) => {
let blog= await Blog.findById(req.params.id)

if (!body.likes)
{ console.log(body.comments)
{ // console.log(body.comments)
var mongoose = require('mongoose');
var ObjectId = mongoose.Types.ObjectId;
var id1 = new ObjectId;
Expand All @@ -86,7 +86,7 @@ blogsRouter.put('/:id', async(req, resp, next) => {
}
else
{
console.log('from put')
//console.log('from put')
try {
const blog = {
title: body.title,
Expand All @@ -95,7 +95,7 @@ blogsRouter.put('/:id', async(req, resp, next) => {
likes: body.likes
}
const updateblog = await Blog.findByIdAndUpdate(req.params.id, blog, { new: true })
console.log('inside ', updateblog)
//console.log('inside ', updateblog)
resp.json(updateblog.toJSON())

} catch (excep) { next(excep) }
Expand Down
12 changes: 12 additions & 0 deletions controllers/testingRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const router = require('express').Router()
const Blog = require('../models/Blog')
const User = require('../models/User')

router.post('/reset', async (request, response) => {
await Blog.deleteMany({})
await User.deleteMany({})

response.status(204).end()
})

module.exports = router
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"start": "cross-env NODE_ENV=production node index.js",
"watch": "cross-env NODE_ENV=development nodemon index.js",
"lint": "eslint .",
"test": "cross-env NODE_ENV=test jest --verbose --runInBand"
"test": "cross-env NODE_ENV=test jest --verbose --runInBand",
"start:test": "cross-env NODE_ENV=test node index.js"
},
"author": "Saddam Mohsen",
"license": "MIT",
Expand Down
Loading

0 comments on commit e8563ee

Please sign in to comment.