-
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
30 changed files
with
2,697 additions
and
1,067 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[{lib,tasks,test}/**.js] | ||
indent_style = space | ||
indent_size = 2 |
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,25 +1,29 @@ | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import path from "path"; | ||
import fs from "fs"; | ||
|
||
import dotenv from 'dotenv'; | ||
import config from 'nconf'; | ||
import dotenv from "dotenv"; | ||
import config from "nconf"; | ||
|
||
dotenv.config(); | ||
|
||
config.argv() // Load config from command line | ||
.env({ lowerCase: true, separator: '__' }); // Load config from enviromental variables and dotenv | ||
config | ||
.argv() // Load config from command line | ||
.env({ lowerCase: true, separator: "__" }); // Load config from enviromental variables and dotenv | ||
|
||
let defaultConfig = path.resolve( path.dirname(__filename), 'config.json'); | ||
let enviromentalConfig = path.resolve( path.dirname(__filename), config.get( 'NODE_ENV' ) + '.json'); | ||
let defaultConfig = path.resolve(path.dirname(__filename), "config.json"); | ||
let enviromentalConfig = path.resolve( | ||
path.dirname(__filename), | ||
config.get("NODE_ENV") + ".json" | ||
); | ||
|
||
// Load enviromental config from file. Enviromental config must be loaded before default config. | ||
if( fs.existsSync(enviromentalConfig) ) { | ||
config.file('enviromental', { file: enviromentalConfig }); | ||
if (fs.existsSync(enviromentalConfig)) { | ||
config.file("enviromental", { file: enviromentalConfig }); | ||
} | ||
|
||
// Load default config from file. Default config must be loaded last to not overwrite enviromental config. | ||
if( fs.existsSync(defaultConfig) ) { | ||
config.file('default', { file: defaultConfig }); | ||
if (fs.existsSync(defaultConfig)) { | ||
config.file("default", { file: defaultConfig }); | ||
} | ||
|
||
export default config; | ||
export default config; |
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,5 @@ | ||
import config from './config.js'; | ||
import mongodburl from './mongodb.js'; | ||
import redisurl from './redis.js'; | ||
import config from "./config.js"; | ||
import mongodburl from "./mongodb.js"; | ||
import redisurl from "./redis.js"; | ||
|
||
export { config as default, mongodburl, redisurl }; | ||
export { config as default, mongodburl, redisurl }; |
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,46 +1,46 @@ | ||
import config from 'nconf'; | ||
import { URL } from 'url'; | ||
import config from "nconf"; | ||
import { URL } from "url"; | ||
|
||
let env, mongodburl; | ||
|
||
/** | ||
* Some cloud services provide single environment variable to connect | ||
* Some cloud services provide single environment variable to connect | ||
* mongodb instance. We do not want to hard code this variable so it | ||
* is configurable. | ||
*/ | ||
env = config.get('mongodb:env'); | ||
env = config.get("mongodb:env"); | ||
|
||
if( typeof env !== 'undefined' ) { | ||
mongodburl = config.get(env.toLowerCase()); | ||
if (typeof env !== "undefined") { | ||
mongodburl = config.get(env.toLowerCase()); | ||
} | ||
|
||
/** | ||
* If there is no provided environment variable build url with config | ||
*/ | ||
if( typeof mongodburl === 'undefined' ) { | ||
mongodburl = new URL('mongodb://localhost'); | ||
if (typeof mongodburl === "undefined") { | ||
mongodburl = new URL("mongodb://localhost"); | ||
|
||
if( typeof config.get('mongodb:host') !== 'undefined' ) { | ||
mongodburl.hostname = config.get('mongodb:host'); | ||
} | ||
if (typeof config.get("mongodb:host") !== "undefined") { | ||
mongodburl.hostname = config.get("mongodb:host"); | ||
} | ||
|
||
if( typeof config.get('mongodb:username') !== 'undefined' ) { | ||
mongodburl.username = config.get('mongodb:username'); | ||
} | ||
if (typeof config.get("mongodb:username") !== "undefined") { | ||
mongodburl.username = config.get("mongodb:username"); | ||
} | ||
|
||
if( typeof config.get('mongodb:password') !== 'undefined' ) { | ||
mongodburl.password = config.get('mongodb:password'); | ||
} | ||
if (typeof config.get("mongodb:password") !== "undefined") { | ||
mongodburl.password = config.get("mongodb:password"); | ||
} | ||
|
||
if( typeof config.get('mongodb:port') !== 'undefined' ) { | ||
mongodburl.port = config.get('mongodb:port'); | ||
} | ||
if (typeof config.get("mongodb:port") !== "undefined") { | ||
mongodburl.port = config.get("mongodb:port"); | ||
} | ||
|
||
if( typeof config.get('mongodb:name') !== 'undefined' ) { | ||
mongodburl.pathname = config.get('mongodb:name'); | ||
} | ||
if (typeof config.get("mongodb:name") !== "undefined") { | ||
mongodburl.pathname = config.get("mongodb:name"); | ||
} | ||
|
||
mongodburl = mongodburl.toString(); | ||
mongodburl = mongodburl.toString(); | ||
} | ||
|
||
export default mongodburl; | ||
export default 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 |
---|---|---|
@@ -1,42 +1,42 @@ | ||
import config from 'nconf'; | ||
import { URL } from 'url'; | ||
import config from "nconf"; | ||
import { URL } from "url"; | ||
|
||
let env, redisurl; | ||
|
||
/** | ||
* Some cloud services provide single environment variable to connect | ||
* Some cloud services provide single environment variable to connect | ||
* redis instance. We do not want to hard code this variable so it | ||
* is configurable. | ||
*/ | ||
env = config.get('redis:env'); | ||
env = config.get("redis:env"); | ||
|
||
if( typeof env !== 'undefined' ) { | ||
redisurl = config.get(env.toLowerCase()); | ||
if (typeof env !== "undefined") { | ||
redisurl = config.get(env.toLowerCase()); | ||
} | ||
|
||
/** | ||
* If there is no provided environment variable build url with config | ||
*/ | ||
if( typeof redisurl === 'undefined' ) { | ||
redisurl = new URL('redis://localhost'); | ||
if (typeof redisurl === "undefined") { | ||
redisurl = new URL("redis://localhost"); | ||
|
||
if( typeof config.get('redis:host') !== 'undefined' ) { | ||
redisurl.hostname = config.get('redis:host'); | ||
} | ||
if (typeof config.get("redis:host") !== "undefined") { | ||
redisurl.hostname = config.get("redis:host"); | ||
} | ||
|
||
if( typeof config.get('redis:username') !== 'undefined' ) { | ||
redisurl.username = config.get('redis:username'); | ||
} | ||
if (typeof config.get("redis:username") !== "undefined") { | ||
redisurl.username = config.get("redis:username"); | ||
} | ||
|
||
if( typeof config.get('redis:password') !== 'undefined' ) { | ||
redisurl.password = config.get('redis:password'); | ||
} | ||
if (typeof config.get("redis:password") !== "undefined") { | ||
redisurl.password = config.get("redis:password"); | ||
} | ||
|
||
if( typeof config.get('redis:port') !== 'undefined' ) { | ||
redisurl.port = config.get('redis:port'); | ||
} | ||
if (typeof config.get("redis:port") !== "undefined") { | ||
redisurl.port = config.get("redis:port"); | ||
} | ||
|
||
redisurl = redisurl.toString(); | ||
redisurl = redisurl.toString(); | ||
} | ||
|
||
export default redisurl; | ||
export default redisurl; |
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 +1 @@ | ||
import './mongodb.js'; | ||
import "./mongodb.js"; |
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,5 @@ | ||
import mongoose from 'mongoose'; | ||
import mongoose from "mongoose"; | ||
|
||
import { mongodburl } from './../config/'; | ||
import { mongodburl } from "./../config/"; | ||
|
||
mongoose.connect(mongodburl); | ||
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 |
---|---|---|
@@ -1,22 +1,32 @@ | ||
import fs from 'fs'; | ||
import fs from "fs"; | ||
|
||
import readChunk from 'read-chunk'; | ||
import fileType from 'file-type'; | ||
import readChunk from "read-chunk"; | ||
import fileType from "file-type"; | ||
|
||
/** | ||
* Entity class used for mongoose model | ||
*/ | ||
export default class File { | ||
|
||
resolveSize() { | ||
|
||
let stats = fs.statSync(this.path); | ||
|
||
return stats.size; | ||
} | ||
|
||
resolveMimeType() { | ||
|
||
let buffer = readChunk.sync(this.path, 0, 4100); | ||
let type = fileType(buffer); | ||
|
||
return type.mime; | ||
} | ||
} | ||
/** | ||
* Resolve size from file path. | ||
* | ||
* @returns {number} File size. | ||
*/ | ||
resolveSize() { | ||
let stats = fs.statSync(this.path); | ||
|
||
return stats.size; | ||
} | ||
|
||
/** | ||
* Resolve mime type from file chunk. | ||
* | ||
* @returns {string} File mime type. | ||
*/ | ||
resolveMimeType() { | ||
let buffer = readChunk.sync(this.path, 0, 4100); | ||
let type = fileType(buffer); | ||
|
||
return type.mime; | ||
} | ||
} |
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,3 +1,6 @@ | ||
import File from './file'; | ||
import File from "./file"; | ||
|
||
export default class Image extends File {} | ||
/** | ||
* Entity class used for mongoose model | ||
*/ | ||
export default class Image extends File {} |
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,19 +1,21 @@ | ||
import config from './config/'; | ||
import db from './db/'; | ||
import config from "./config/"; | ||
import "./db/"; | ||
|
||
import web from './web/'; | ||
import { optimize } from './worker/'; | ||
import web from "./web/"; | ||
import { optimize } from "./worker/"; | ||
|
||
import logger from 'winston'; | ||
import logger from "winston"; | ||
|
||
let type = config.get('type'); | ||
let type = config.get("type"); | ||
|
||
logger.info(`Starting '${type}' process`, { pid: process.pid }) | ||
logger.info(`Starting '${type}' process`, { pid: process.pid }); | ||
|
||
if (type === 'web') { | ||
web(); | ||
} else if (type === 'worker') { | ||
optimize(); | ||
if (type === "web") { | ||
web(); | ||
} else if (type === "worker") { | ||
optimize(); | ||
} else { | ||
throw new Error(`"${type}" is an unsupported process type. Use one of: "web", "worker"!`); | ||
} | ||
throw new Error( | ||
`"${type}" is an unsupported process type. Use one of: "web", "worker"!` | ||
); | ||
} |
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
Oops, something went wrong.