diff --git a/.babelrc.js b/.babelrc.js new file mode 100644 index 0000000..68413d0 --- /dev/null +++ b/.babelrc.js @@ -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 }, + ], + ], +}; \ No newline at end of file diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..bc57e48 --- /dev/null +++ b/.eslintrc @@ -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": {} + } + } +} diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..12474f2 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,7 @@ +{ + "printWidth": 100, + "trailingComma": "all", + "tabWidth": 4, + "semi": true, + "singleQuote": false +} \ No newline at end of file diff --git a/app/config/env-config.js b/app/config/env-config.js new file mode 100644 index 0000000..86626b3 --- /dev/null +++ b/app/config/env-config.js @@ -0,0 +1,6 @@ +const APP_PORT = process.env.PORT || 3000; + +// variables de entorno +module.exports = { + "process.env.PORT": APP_PORT, +}; diff --git a/app/public/favicon.ico b/app/public/favicon.ico new file mode 100644 index 0000000..0339e15 Binary files /dev/null and b/app/public/favicon.ico differ diff --git a/app/src/controllers/index.js b/app/src/controllers/index.js new file mode 100644 index 0000000..e69de29 diff --git a/app/src/models/index.js b/app/src/models/index.js new file mode 100644 index 0000000..e69de29 diff --git a/app/src/server/index.js b/app/src/server/index.js new file mode 100644 index 0000000..4157bb6 --- /dev/null +++ b/app/src/server/index.js @@ -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}`); + } +}); diff --git a/app/src/server/router.js b/app/src/server/router.js new file mode 100644 index 0000000..a404093 --- /dev/null +++ b/app/src/server/router.js @@ -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; diff --git a/app/src/tools/index.js b/app/src/tools/index.js new file mode 100644 index 0000000..e69de29 diff --git a/nodemon.json b/nodemon.json new file mode 100644 index 0000000..f58bd5a --- /dev/null +++ b/nodemon.json @@ -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" +} \ No newline at end of file diff --git a/package.json b/package.json index 56d6f2b..f267b2c 100644 --- a/package.json +++ b/package.json @@ -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" } -} \ No newline at end of file +} diff --git a/run_app.js b/run_app.js new file mode 100644 index 0000000..3fe5814 --- /dev/null +++ b/run_app.js @@ -0,0 +1,5 @@ +/** + * Launches the app server. + */ +require("@babel/register"); // eslint-disable-line +require("./app/src/server/index");