-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
159 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,27 @@ | ||
import mongoose from "mongoose"; | ||
import logger from "winston"; | ||
|
||
import { mongodburl } from "./../config/"; | ||
|
||
mongoose.connection.on("connected", function() { | ||
logger.info("MongoDB connected."); | ||
}); | ||
|
||
mongoose.connection.once("open", function() { | ||
logger.info("MongoDB connection opened."); | ||
}); | ||
|
||
mongoose.connection.on("disconnected", function() { | ||
logger.info("MongoDB disconnected."); | ||
}); | ||
|
||
mongoose.connection.on("reconnected", function() { | ||
logger.info("MongoDB reconnected."); | ||
}); | ||
|
||
mongoose.connection.on("error", function(err) { | ||
logger.error("MongoDB error."); | ||
logger.error(err); | ||
}); | ||
|
||
mongoose.connect(mongodburl); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Image from "./../models/image"; | ||
|
||
export default { | ||
findById(id) { | ||
return new Promise(function(resolve, reject) { | ||
Image.findById(id, function(err, image) { | ||
if (err) { | ||
return reject(err); | ||
} | ||
|
||
resolve(image); | ||
}); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import image from "./image.js"; | ||
|
||
export { image }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import boom from "boom"; | ||
|
||
/** | ||
* Error middleware. | ||
* | ||
* Error middleware will catch any error throwed in controllers | ||
* and pass it to express next function. | ||
* | ||
* @param {Function} fn - Express route controller action. | ||
* | ||
* @returns {Function} Express middleware function. | ||
*/ | ||
function error(fn) { | ||
return function(req, res, next) { | ||
Promise.resolve(fn(req, res, next)).catch(err => { | ||
if (!err.isBoom) { | ||
return next(boom.badImplementation(err)); | ||
} | ||
|
||
return next(err); | ||
}); | ||
}; | ||
} | ||
|
||
export default error; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import boom from "boom"; | ||
|
||
import error from "./../middlewares/error.js"; | ||
|
||
/** | ||
* Not found route. | ||
* | ||
* Throw not found error if any routes get here. | ||
* | ||
* @param {Object} app - Express app. | ||
* | ||
* @returns {void} Returns nothing. | ||
*/ | ||
function notfound(app) { | ||
// Match all routes | ||
app.route("*").get( | ||
error(function(req, res) { | ||
throw boom.notFound( | ||
"The URI requested is invalid or the resource requested does not exist." | ||
); | ||
}) | ||
); | ||
} | ||
|
||
export default notfound; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -967,6 +967,12 @@ [email protected]: | |
dependencies: | ||
hoek "4.x.x" | ||
|
||
boom@^7.2.0: | ||
version "7.2.0" | ||
resolved "https://registry.yarnpkg.com/boom/-/boom-7.2.0.tgz#2bff24a55565767fde869ec808317eb10c48e966" | ||
dependencies: | ||
hoek "5.x.x" | ||
|
||
boxen@^1.2.1: | ||
version "1.3.0" | ||
resolved "https://registry.yarnpkg.com/boxen/-/boxen-1.3.0.tgz#55c6c39a8ba58d9c61ad22cd877532deb665a20b" | ||
|