{"id":17091250,"url":"https://github.com/robertomachorro/mvc-webapp","last_synced_at":"2025-04-12T22:35:58.714Z","repository":{"id":42844064,"uuid":"245745794","full_name":"RobertoMachorro/mvc-webapp","owner":"RobertoMachorro","description":"A simple framework for MVC web applications and RESTful APIs.","archived":false,"fork":false,"pushed_at":"2025-02-25T03:24:35.000Z","size":1159,"stargazers_count":2,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T22:39:14.477Z","etag":null,"topics":["framework","node","node-module","nodejs","npm","npm-module","npm-package","webapp"],"latest_commit_sha":null,"homepage":"https://roberto.machorro.net/mvc-webapp/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RobertoMachorro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-08T03:31:30.000Z","updated_at":"2025-02-25T03:24:39.000Z","dependencies_parsed_at":"2023-02-11T21:46:08.023Z","dependency_job_id":"198566ee-d1ac-4180-bdc9-9fb7b0fc92eb","html_url":"https://github.com/RobertoMachorro/mvc-webapp","commit_stats":{"total_commits":91,"total_committers":2,"mean_commits":45.5,"dds":0.06593406593406592,"last_synced_commit":"13dea1c73b6326f59f4d0bb06d2aea225ed8fd97"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobertoMachorro%2Fmvc-webapp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobertoMachorro%2Fmvc-webapp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobertoMachorro%2Fmvc-webapp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobertoMachorro%2Fmvc-webapp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RobertoMachorro","download_url":"https://codeload.github.com/RobertoMachorro/mvc-webapp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248642605,"owners_count":21138352,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["framework","node","node-module","nodejs","npm","npm-module","npm-package","webapp"],"created_at":"2024-10-14T13:58:05.153Z","updated_at":"2025-04-12T22:35:58.692Z","avatar_url":"https://github.com/RobertoMachorro.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![GitHub](https://img.shields.io/github/license/RobertoMachorro/mvc-webapp)\n![GitHub release (latest by date)](https://img.shields.io/github/v/release/RobertoMachorro/mvc-webapp)\n![build](https://github.com/RobertoMachorro/mvc-webapp/workflows/build/badge.svg)\n\n# mvc-webapp node module\n\nA simple framework for MVC web applications and RESTful APIs.\n\n## Features\n\n* Docker container ready\n* Express 5 based HTTP handling and routes\n* Familiar MVC folder structure and URL paths (controller per file, public folder for static content, etc)\n* Optional shared session management using Redis\n* CORS support (HTTP OPTIONS)\n* Flexible logging formatting using Morgan (defaults to Apache style)\n* Out of the box support for EJS templates in Views, and partials\n* Use any Node based data access module for storage\n* Custom error handling\n* Tiny and clean; outside of NPM dependencies, the code is about ~200 lines\n\n## Setup and First Webapp\n\n1. Follow these steps to get started with your first mvc-webapp:\n\n```bash\nmkdir test-app\ncd test-app\nnpm init\nnpm install express@5 --save\nnpm install mvc-webapp --save\nmkdir -p application/models\nmkdir -p application/controllers\nmkdir -p application/views\nmkdir -p application/adapters\nmkdir -p application/public\n```\n\nAt some point this will be automated by a script, for now, it will involve some keystrokes.\n\n2. Add an entry point app.js on the root folder. This contains your app options and can be configurable via env-vars for container usage:\n\n```javascript\n#!/usr/bin/env node\n\nconst webapp = require('mvc-webapp')\n\nwebapp.run({\n\tapplicationRoot: process.env.PWD,\n\tlistenPort: process.env.PORT || '3000',\n\tsessionRedisUrl: process.env.REDISCLOUD_URL || undefined,\n\tsessionSecret: process.env.SESSION_SECRET || undefined,\n\tredirectSecure: true,\n\tallowCORS: false,\n\tviewEngine: 'ejs', // Optional: Pug, Handlebars, EJS, etc\n\tloggerFormat: 'common', // Morgan formats\n\ttrustProxy: true,\n\tnotfoundMiddleware: (request, response, next) =\u003e {\n\t\tresponse.status(404).json({\n\t\t\tcode: 404,\n\t\t\tmessage: 'Sorry! File Not Found'\n\t\t})\n\t},\n\terrorMiddleware: (error, request, response, _) =\u003e {\n\t\tif (request.xhr) {\n\t\t\tresponse.status(500).json({\n\t\t\t\tcode: 500,\n\t\t\t\tmessage: (error.message)? error.message : error,\n\t\t\t\tstack: request.app.get('env') === 'development' ? error.stack : ''\n\t\t\t})\n\t\t} else {\n\t\t\tresponse.render('error', {\n\t\t\t\tpageTitle: 'Oops!',\n\t\t\t\tstatus: 500,\n\t\t\t\tmessage: (error.message)? error.message : error,\n\t\t\t\tstack: request.app.get('env') === 'development' ? error.stack : '',\n\t\t\t})\n\t\t}\n\t},\n})\n```\n\nThis is the minimal amount of options you can give, sensible and secure default values are given for everything else:\n\n```javascript\n#!/usr/bin/env node\n\nconst webapp = require('mvc-webapp')\n\nwebapp.run({\n\t// Mandatory\n\tapplicationRoot: process.env.PWD,\n\tlistenPort: process.env.PORT || '3000',\n\n\t// Optional Redis Session Management\n\t// sessionRedisUrl: undefined,\n\t// sessionSecret: undefined,\n\n\t// Optional Security Related\n\t// redirectSecure: false,\n\t// allowCORS: false,\n\t// trustProxy: false,\n\n\t// Optional Framework\n\t// viewEngine: undefined, // Pug, Handlebars, EJS, etc\n\t// loggerFormat: 'common', // Morgan formats\n\n\t// Optional Error Handling\n\t// notfoundMiddleware: undefined,\n\t// errorMiddleware: undefined,\n})\n```\n\nThe error handling can be customized to return plain JSON, HTTP codes or an EJS rendered page, your choice.\n\n3. Add an initial controller, this will be automatically mapped to a path (login.js becomes /login/\u003cmethod\u003e/\u003cparams\u003e):\n\n```javascript\nexports.actions = controller =\u003e {\n\tcontroller.get('/', (request, response, _) =\u003e {\n\t\tresponse.json({\n\t\t\tstatus: 'Sample status...',\n\t\t\tdata: null,\n\t\t})\n\t})\n\t\n\tcontroller.get('/async', async (request, response) =\u003e {\n\t\tconst hi = await Promise.resolve('Hi!')\n\t\tresponse.send(hi)\n\t})\n\n\tcontroller.get('/fail', async (request, response) =\u003e {\n\t\tawait Promise.reject('REJECTED!')\n\t})\n\n\tcontroller.get('/denied', async (request, response) =\u003e {\n\t\tresponse.status(403).send('Not here')\n\t})\n\n\treturn controller\n}\n```\n\nThis should be familiar to any Express user. A special exception is made for the index.js controller file, this is mapped to the root / folder. Additionally, any routes inside that controller, get appended as a method.\n\nIn order to render a view, invoke the view (file)name in the res.render call:\n\n```javascript\nresponse.render('index', {\n\ttitle: 'Homepage',\n\tuser: 'octopie'\n})\n```\n\n4. Run using **npm start** or **node app.js** - added the env var _DEBUG=\"mvc-webapp:*\"_ to see what the framework is doing behind the scenes.\n\n## Docker Support\n\nAdd the following file to the root folder and _docker build_:\n\n```Dockerfile\nFROM node:latest\n\nWORKDIR /app\nADD . /app\n\nRUN npm install\n\nCMD [\"npm\",\"start\"]\n```\n\n## Also Checkout\n\n1. [EJS Templates](https://ejs.co) - this is what the views use\n2. [Express](https://expressjs.com) - this is what powers the HTTP communication\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertomachorro%2Fmvc-webapp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobertomachorro%2Fmvc-webapp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertomachorro%2Fmvc-webapp/lists"}