Skip to content

camelaissani/frontexpress-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

frontexpress-demo

Smallest project for starting using frontexpress framework.

image

Quick Start

Clone the git repository:

$ git clone git@github.com:camelaissani/frontexpress-demo.git
$ cd frontexpress-demo

Install dependencies:

$ npm install

Start the server:

$ npm start

Objective

Create a Single Page Application (SPA) in which the routing is managed by frontexpress.

We created a frontexpress application:

// Frontend application
const app = frontexpress();

This application listens two kind of routes:

// api routes (ajax requests)
app.use(apiRouter);

// page routes (complete page refresh)
app.use(pageRouter);

It pops up a dialog to ask sign in when the HTTP error 401 is received

// React on http 401 (Unauthorized need to sign in to access)
app.use((req, res, next)  => {
    if (res.status === 401) {
        window.alert('Your are not authenticated!\n\nPlease sign in.');
        app.httpGet(`/api/login?ori_req=${encodeURIComponent(req.uri)}`);
    } else {
        next();
    }
});

The menu selection is managed through out routes

// On update content select the corresponding menu
router.get((req, res, next) => {
    menu.selection(req.uri);
    next();
});

For more look at the sources.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published