Skip to content

Commit

Permalink
Merge pull request #9 from OrcaPracticas/add/init
Browse files Browse the repository at this point in the history
⚙️ Configuración inicial
  • Loading branch information
konami12 authored Jun 21, 2020
2 parents 8c1a7fd + ab62ed0 commit 7e589f5
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 4 deletions.
22 changes: 22 additions & 0 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const ENV = require("./app/config/env-config");

module.exports = {
presets: ["@babel/preset-env"],
plugins: [
"inline-json-import",
[
"module-resolver",
{
alias: {
"Controller": "./app/src/controller/",
"Models": "./app/src/models/",
"Tools": "./app/src/tools/",
}
}
],
[
"transform-define",
{ ...ENV },
],
],
};
20 changes: 20 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": [
"airbnb",
"prettier"
],
"parser": "babel-eslint",
"plugins": [
"prettier",
"module-resolver"
],
"rules": {
"prettier/prettier": "error",
"module-resolver/use-alias": 2
},
"settings": {
"import/resolver": {
"babel-module": {}
}
}
}
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"printWidth": 100,
"trailingComma": "all",
"tabWidth": 4,
"semi": true,
"singleQuote": false
}
6 changes: 6 additions & 0 deletions app/config/env-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const APP_PORT = process.env.PORT || 3000;

// variables de entorno
module.exports = {
"process.env.PORT": APP_PORT,
};
Binary file added app/public/favicon.ico
Binary file not shown.
Empty file added app/src/controllers/index.js
Empty file.
Empty file added app/src/models/index.js
Empty file.
46 changes: 46 additions & 0 deletions app/src/server/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import Compression from "compression";
import Cors from "cors";
import Express, { Router, static as Statics } from "express";
import BodyParser from "body-parser";
import Helmet, { frameguard } from "helmet";
import Path from "path";

import ApiRouter from "./router";

// ======================== CONSTANTES ======================== //

const APP_PORT = process.env.PORT;
const ROOT_PATH = Path.join(__dirname, "../../");
const Server = Express();

// ==================== COMNFIGURACIONES ==================== //

Server.use(Cors());

Server.use(Helmet());
Server.use(frameguard({ action: "allow-from", domain: "*" }));

Server.use(Compression({ threshold: 0 }));

// ==================== PARSEO DE PARAMETROS ==================== //

Server.use(BodyParser.urlencoded({ extended: false }));
Server.use(BodyParser.json());

// ==================== ARCHIVOS STATICOS ==================== //

Server.use("/", Statics(`${ROOT_PATH}/public/`));

// ===================== MANEJO DE RUTAS ====================== //

Server.use(ApiRouter(Router));

// ====================== ESTABLECIENDO CONEXIÓN ====================== //

Server.listen(APP_PORT, (error) => {
if (error) {
console.log(error);
} else {
console.log(`Servidro listo ${APP_PORT}`);
}
});
11 changes: 11 additions & 0 deletions app/src/server/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const ApiRouter = (router) => {
const Router = router();
Router.use((request, response) => {
response.status(200);
response.send("<h1>Hola Mundo !</h1>");
});

return Router;
};

export default ApiRouter;
Empty file added app/src/tools/index.js
Empty file.
14 changes: 14 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"verbose": true,
"ignore": [
"node_modules",
"./app/public"
],
"watch": [
"./app/src",
"./app/src/controller",
"./app/src/model",
"./run_app.js"
],
"ext": "js json"
}
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,21 @@
"@babel/cli": "7.10.3",
"@babel/core": "7.10.3",
"@babel/node": "7.10.3",
"babel-eslint": "10.1.0",
"@babel/preset-env": "7.10.3",
"@babel/register": "7.10.3",
"babel-eslint": "10.1.0",
"babel-plugin-inline-json-import": "0.3.2",
"babel-plugin-module-resolver": "4.0.0",
"babel-plugin-transform-define": "2.0.0",
"eslint": "7.2.0",
"eslint-config-airbnb": "18.1.0",
"eslint-config-prettier": "6.11.0",
"eslint-import-resolver-babel-module": "5.1.2",
"eslint-plugin-import": "2.21.2",
"eslint-plugin-jsx-a11y": "6.2.3",
"eslint-plugin-module-resolver": "0.16.0",
"eslint-plugin-prettier": "3.1.4",
"prettier": "2.0.5",
"nodemon": "2.0.4"
"nodemon": "2.0.4",
"prettier": "2.0.5"
}
}
}
5 changes: 5 additions & 0 deletions run_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* Launches the app server.
*/
require("@babel/register"); // eslint-disable-line
require("./app/src/server/index");

0 comments on commit 7e589f5

Please sign in to comment.