Smallest project for starting using frontexpress framework.
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
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.