Giter VIP home page Giter VIP logo

simplewebjs's Introduction

Express.js MVC Server with Handlebars and Sneat Admin Template + Built-in database-less Authentication

This repository contains an Express.js server structured in the MVC (Model-View-Controller) pattern, using Handlebars (hbs) for templating and incorporating the Sneat Admin Template for the frontend with pre built in authentication by json. it uses cookies to store the user session.

Table of Contents

Installation

  1. Clone the repository:

     git clone https://github.com/hassankhurram/simplewebjs.git
     cd simplewebjs
  2. Install dependencies:

    npm install
  3. Environment Variables:

    you can rename example.env to .env and set the variables as per your needs.

    NODE_ENV=development
    PORT=7896
    APP_TITLE=BatchCom CE
    BASE_URL=https://localhost:7896
    PASS_SALT_ROUNDS=10
    JWT_SECRET="abc1234"
    JWT_EXPIRES_IN=3600s
  4. Docker:

    DockerFile and docker-compose file is included:

    docker compose up --build -d

Usage

In development:

npm run dev

In Production:

npm run start

Routes

Routers are automatically loaded based on their name and class name by routers/routes.js file, it loops all the files in the folder routes and loads them for you so that you don't have to manually import them.

i.e.

authRouter.js >

   export default class AuthRouter extends BaseRouter{
      static urlPath = "/auth";
      constructor(router) {
         super(router, AuthController);
         this.router.get('/login', AuthController.generateLoginPage);
         this.router.get('/logout', AuthController.logOutUser);
         this.router.post("/submit_login", AuthController.attemptLogin);
      }
   };

file name and class name should be the same with naming convention in mind.

The variable urlPath defines the prefix of the URL per router Syntax: http://localhost:7896/:urlPath/url i.ie

   static urlPath = "/auth";
  http://localhost:7896/auth/

Controllers

Controllers are simple having static functions in the class, can be exported and called, take an example of working of AuthController with AuthRouter

example:

export class MyController extends BaseController {

   constructor() {
      super();
   }

   static async someRandomController(req, res) {
      
   }
}

Views

Views are placed inside pages folder, having layout and partials.

Layouts are the structure in the page (component is loaded) along with partials ( repeated parts of the code. ) The variables are populated using handlebars. you can also use ejs instead of handlebars. The pages are generated using utils/generator.js file.

Layout:

.
├── layouts
│   ├── authcontext.hbs
│   ├── basic.hbs
│   └── dashboardcontext.hbs
├── pages
│   ├── http
│   │   └── error.hbs
│   ├── index.hbs
│   └── login.hbs
└── partials
   ├── footer.hbs
   ├── navbar.hbs
   ├── scripts.hbs
   └── sidebar.hbs

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Acknowledgments

This project was inspired by the following resources:

Feel free to contact me on [email protected] if you have any questions or suggestions or raise an issue if needed.

simplewebjs's People

Contributors

hassankhurram avatar

Watchers

 avatar

Forkers

tehreemwaris2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.