Skip to content

Commit b48d7c4

Browse files
committed
Cleaning repo for full refactoring
2 parents d8a9e5d + a4d75ef commit b48d7c4

18 files changed

+469
-57
lines changed

.gitignore

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
.DS_Store
22
node_modules
3-
.compiled
4-
dist
53
.settings
64
.idea
75
*.log
8-
defs
9-
tmp
6+
.vscode

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM node:latest
22
EXPOSE 8080
33
EXPOSE 80
4-
RUN npm install -g gulp mocha pm2
4+
RUN npm install -g mocha
55
RUN mkdir /app
6-
WORKDIR /app
6+
WORKDIR /app

gulpfile.js

-23
This file was deleted.

jsconfig.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES6",
4+
"module": "commonjs"
5+
}
6+
}

package.json

+20-27
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
{
2-
"name": "server",
3-
"version": "3.2.0",
4-
"description": "RioBus server application",
5-
"main": ".compiled/src/index.js",
2+
"name": "proxy",
3+
"version": "4.0.0",
4+
"description": "RioBus proxy application",
5+
"main": "src/app.js",
66
"scripts": {
7-
"test": "gulp buildTest && mocha .compiled/test/**/* --timeout 10000",
8-
"build": "gulp build",
9-
"start": "gulp build && node .compiled/src/index.js"
7+
"test": "mocha test/**/*",
8+
"start": "node src/app.js"
109
},
1110
"repository": {
1211
"type": "git",
13-
"url": "https://github.com/riobus/server"
12+
"url": "https://github.com/riobus/proxy"
1413
},
1514
"keywords": [
1615
"riobus",
@@ -27,29 +26,23 @@
2726
"wrapper",
2827
"infrastructure"
2928
],
30-
"author": "Fred Souza <[email protected]> (http://fmsouza.github.io)",
31-
"license": "http://github.com/RioBus/server/blob/master/LICENSE",
29+
"license": "http://github.com/RioBus/proxy/blob/master/LICENSE",
3230
"bugs": {
33-
"url": "http://github.com/RioBus/server/issues"
31+
"url": "http://github.com/RioBus/proxy/issues"
3432
},
35-
"homepage": "http://github.com/RioBus/server",
33+
"homepage": "http://github.com/RioBus/proxy",
3634
"dependencies": {
37-
"compression": "latest",
38-
"deasync": "latest",
39-
"emailjs": "latest",
40-
"express": "latest",
41-
"fs-extra": "latest",
42-
"moment": "latest",
43-
"moment-timezone": "latest",
44-
"mongodb": "latest",
45-
"nodealytics": "latest",
46-
"request": "latest"
35+
"body-parser": "^1.14.1",
36+
"co": "^4.6.0",
37+
"compression": "^1.5.2",
38+
"express": "^4.13.3",
39+
"fs-extra": "^0.26.0",
40+
"mongodb": "^1.4.4",
41+
"request-promise": "^1.0.2",
42+
"robe": "^0.12.0"
4743
},
4844
"devDependencies": {
49-
"gulp": "latest",
50-
"gulp-load-plugins": "latest",
51-
"gulp-typescript": "latest",
52-
"gulp-util": "^3.0.6",
53-
"mocha": "latest"
45+
"co-mocha": "^1.1.2",
46+
"mocha": "^2.3.3"
5447
}
5548
}

run-container

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/bash
2-
docker run -it --rm -p 8080:8080 -p 80:80 --link mongo:mongo -v $(pwd):/app --name riobus-proxy riobus /bin/bash
2+
docker run -it --rm -p 8080:8080 -p 80:80 --link mongo:mongo -v "$(pwd)":/app --name riobus-proxy nodejs /bin/bash

src/app.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
/* global process; */
3+
const Config = require('./config');
4+
const Core = require('./core');
5+
const LoggerFactory = Core.LoggerFactory;
6+
const Router = Core.Router;
7+
const spawn = require('co');
8+
9+
const logger = LoggerFactory.getRuntimeLogger();
10+
11+
spawn(function* main(){
12+
logger.info('Starting the server...');
13+
14+
// Configuring the RESTful router to handle HTTP requests
15+
let router = new Router();
16+
router.registerResources(Config.resources); // Registering resources to handle the URLs
17+
18+
let server = Config.server;
19+
router.start(server.ip, server.port); // Starting RESTful application
20+
})
21+
.catch(function(error) {
22+
logger.error(error);
23+
process.exit(1);
24+
});

src/config.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* global __dirname, process; */
2+
/**
3+
* Application configuration
4+
* You may use it to describe every global configuration data
5+
*/
6+
module.exports = {
7+
root: __dirname,
8+
logs: {
9+
runtime: `/tmp/riobus/log/runtime-${new Date("Y-m-d").toISOString()}.log`,
10+
server: `/tmp/riobus/log/server-${new Date("Y-m-d").toISOString()}.log`
11+
},
12+
server: {
13+
ip: '0.0.0.0',
14+
port: 8080
15+
},
16+
database: {
17+
dbName: process.env.RIOBUS_DB_NAME || 'riobus',
18+
host: process.env.RIOBUS_DB_HOST || 'localhost',
19+
port: process.env.RIOBUS_DB_PORT || 27017,
20+
user: process.env.RIOBUS_DB_USER || '',
21+
pass: process.env.RIOBUS_DB_PASS || ''
22+
},
23+
analytics: {
24+
ua: process.env.RIOBUS_ANALYTICS_UA || '',
25+
host: process.env.RIOBUS_ANALYTICS_HOST || ''
26+
},
27+
resources: [
28+
'main/mainResource'
29+
]
30+
};

src/core.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const root = './core';
2+
module.exports = {
3+
Database: require(`${root}/database`),
4+
File: require(`${root}/file`),
5+
Http: require(`${root}/http`),
6+
Logger: require(`${root}/log/logger`),
7+
LoggerFactory: require(`${root}/log/loggerFactory`),
8+
Router: require(`${root}/router`)
9+
}

src/core/database.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
const Robe = require('robe');
3+
const Config = require('../config');
4+
5+
class Database {
6+
7+
static connect(config) {
8+
if(!config) config = Config.database;
9+
var url = `${config.host}:${config.port}/${config.dbName}`;
10+
if(config.user!=='' && config.pass!=='') url = `${config.user}:${config.pass}@${url}`;
11+
return Robe.connect(url);
12+
}
13+
}
14+
15+
module.exports = Database;

src/core/file.js

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
'use strict';
2+
/**
3+
* Manipulates files access
4+
* @class {File}
5+
*/
6+
class File {
7+
8+
constructor(path) {
9+
this.fullPath = path;
10+
var splittedPath = path.split('/');
11+
this.file = splittedPath.pop();
12+
this.directory = splittedPath.join('/');
13+
this.fs = require("fs-extra");
14+
this.fs.ensureFileSync(this.fullPath);
15+
}
16+
17+
/**
18+
* Get the full file path
19+
* @return {string}
20+
*/
21+
get filePath() {
22+
return this.fullPath;
23+
}
24+
25+
/**
26+
* Get the directory where the file is
27+
* @return {string}
28+
*/
29+
get dirPath() {
30+
return this.directory;
31+
}
32+
33+
/**
34+
* Get the file name
35+
* @return {string}
36+
*/
37+
get fileName() {
38+
return this.file;
39+
}
40+
41+
/**
42+
* Appends content to end of file
43+
* @param {string} content - Content to be written to the file
44+
* @return {void}
45+
*/
46+
append(content) {
47+
this.fs.appendFileSync(this.fullPath, `${content}\n`);
48+
}
49+
50+
/**
51+
* Writes the given content to a file. Ovewrites if it already has any content.
52+
* @param {string} content - Content to be written to the file
53+
* @return {void}
54+
*/
55+
write(content) {
56+
this.fs.outputFileSync(this.fullPath, `${content}\n`);
57+
}
58+
59+
/**
60+
* Reads the file content
61+
* @return {string}
62+
*/
63+
read() {
64+
return this.fs.readFileSync(this.fullPath, 'utf8');
65+
}
66+
}
67+
module.exports = File;

src/core/http.js

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
'use strict';
2+
const request = require('request-promise');
3+
4+
var optionsObj = {
5+
method: 'GET',
6+
simple: true,
7+
resolveWithFullResponse: true,
8+
json: true
9+
}
10+
/**
11+
* Creates a new synchronized HttpRequest
12+
* @class {Http}
13+
*/
14+
class Http {
15+
16+
/**
17+
* Makes requests through Options object
18+
* @param {Object} options - Options object
19+
* @returns {Promise}
20+
*/
21+
static request(options) {
22+
var data = JSON.parse(JSON.stringify(optionsObj));
23+
for(var key in Object.keys(options)) {
24+
data[key] = options[key];
25+
}
26+
return request(options);
27+
}
28+
29+
/**
30+
* Makes GET request
31+
* @param {string} host - Host URL
32+
* @returns {Promise}
33+
*/
34+
static get(host){
35+
return Http.request({ uri: host });
36+
}
37+
38+
/**
39+
* Makes POST request
40+
* @param {string} host - Host URL
41+
* @param {Object} data - Data to be sent
42+
* @returns {Promise}
43+
*/
44+
static post(host, data){
45+
return Http.request({ method: 'POST', uri: host, body: data });
46+
}
47+
48+
/**
49+
* Makes PUT request
50+
* @param {string} host - Host URL
51+
* @param {Object} options
52+
* @returns {Promise}
53+
*/
54+
static put(host, data){
55+
return Http.request({ method: 'PUT', uri: host, body: data });
56+
}
57+
58+
/**
59+
* Makes DELETE request
60+
* @param {String} host - Host URL
61+
* @returns {Promise}
62+
*/
63+
static delete(host){
64+
return Http.request({ method: 'DELETE', uri: host });
65+
}
66+
}
67+
module.exports = Http;

0 commit comments

Comments
 (0)