An Express.js-Style router for the front-end

Overview

frontexpress

An Express.js-Style router for the front-end.

Code the front-end like the back-end. Same language same framework.

frontexpress demo

Build Status Code Climate Coverage Status dependencies Size Shield npm

import frontexpress from 'frontexpress';

// Front-end application
const app = frontexpress();

// handles http 401
app.use((req, res, next)  => {
    if (res.status === 401) {
        window.alert('You are not authenticated! Please sign in.');
    } else {
        next();
    }
});

app.get('/', (req, res) => {
    document.querySelector('.content').innerHTML = 'Hello World!';
});

app.post('/login/:user', (req, res) => {
    document.querySelector('.content').innerHTML = `Welcome ${req.params.user}!`;
});

// start listening front-end requests (emitted/received)
app.listen();

Features

✔️ You already know ExpressJS then you know FrontExpress

✔️ Simple, minimal core extendable through plugins

✔️ Lighweight framework

✔️ Build your front-end application by handling routes

✔️ Ideal for Single Page Application

✔️ Manage ajax requests and browser history

Installation

From npm repository

$ npm install frontexpress

From bower repository

$ bower install frontexpress

From CDN

On jsDelivr

Documentation

Website and Documentation

Tests

Clone the repository:

$ git clone [email protected]:camelaissani/frontexpress.git
$ cd frontexpress

Install the dependencies and run the test suite:

$ npm install
$ npm test

License

MIT

Comments
  • Make Frontexpress extendable with plug-ins

    Make Frontexpress extendable with plug-ins

    For SPA it would be interesting that when you call the listen () method, you have an option to activate this feature, for example:

    App.listen ({spa: true});

    (Or a default feature of frontexpress)

    Once this option is enabled, the listen () method internally generates a list of paths that appear as a parameter in the get methods invoked. For example:

    App.get ('/ page1', (req, res) => {    // Some-code });

    App.get ('/ page2', (req, res) => {    // Some-code });

    It would generate an array: routes = ['page1', 'page2'], then look for tags that have those paths, use preventDefault to avoid making the request to the server and execute // Some-code when clicked on it

    I think this would help keep the HTML document more semantic as it allows you to use tags like <a href="page1"> Page 1 </a> and avoid requests to the server through calls with AJAX

    Sorry for my english, is not my native language

    Thank you!

    opened by aldebaran798 8
  • I can't get it work

    I can't get it work

    opened by aldebaran798 7
  • History management?

    History management?

    First of all, thanks for a great library. I wonder how I can manage history using Frontexpress? For example when building a SPA, I want to change the URL and make the page load which I've defined earlier with app instance. I've tried using httpGet, but then back button won't work. How can I do this? Thanks

    opened by crdil 5
  • fuck the eslint

    fuck the eslint

    0 info it worked if it ends with ok 1 verbose cli [ 'C:\Program Files\nodejs\node.exe', 1 verbose cli 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js', 1 verbose cli 'run', 1 verbose cli 'lint' ] 2 info using [email protected] 3 info using [email protected] 4 verbose run-script [ 'prelint', 'lint', 'postlint' ] 5 info lifecycle [email protected]~prelint: [email protected] 6 silly lifecycle [email protected]~prelint: no script for prelint, continuing 7 info lifecycle [email protected]~lint: [email protected] 8 verbose lifecycle [email protected]~lint: unsafe-perm in lifecycle true 9 verbose lifecycle [email protected]~lint: PATH: C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin;E:\test\frontexpress\node_modules.bin;C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin;E:\test\frontexpress\node_modules.bin;C:\Users\Administrator\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\Administrator\bin;C:\Python27;C:\Python27\Scripts;C:\Program Files\ImageMagick-7.0.1-Q16;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\CCM;C:\ProgramData\chocolatey\bin;D:\Python27\Scripts;C:\Python27\Scripts;C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32;C:\Users\Administrator\AppData\Local\Programs\Python\Script;C:\Python27;C:\Python27\Scripts;C:\Python36;C:\Python36\Scripts;C:\Program Files (x86)\Yarn\bin;C:\Program Files\nodejs;C:\Program Files\node profiler;D:\Program Files\TortoiseGit\bin;C:\Program Files (x86)\Microsoft VS Code\bin;C:\Users\Administrator\AppData\Local\Yarn\bin;C:\Users\Administrator\AppData\Roaming\npm;C:\Program Files\Docker Toolbox;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl 10 verbose lifecycle [email protected]~lint: CWD: E:\test\frontexpress 11 silly lifecycle [email protected]~lint: Args: [ '/d /s /c', 'eslint .' ] 12 silly lifecycle [email protected]~lint: Returned: code: 1 signal: null 13 info lifecycle [email protected]~lint: Failed to exec lint script 14 verbose stack Error: [email protected] lint: eslint . 14 verbose stack Exit status 1 14 verbose stack at EventEmitter. (C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:283:16) 14 verbose stack at emitTwo (events.js:125:13) 14 verbose stack at EventEmitter.emit (events.js:213:7) 14 verbose stack at ChildProcess. (C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:40:14) 14 verbose stack at emitTwo (events.js:125:13) 14 verbose stack at ChildProcess.emit (events.js:213:7) 14 verbose stack at maybeClose (internal/child_process.js:887:16) 14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:208:5) 15 verbose pkgid [email protected] 16 verbose cwd E:\test\frontexpress 17 verbose Windows_NT 6.1.7601 18 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "run" "lint" 19 verbose node v8.1.0 20 verbose npm v5.0.3 21 error code ELIFECYCLE 22 error errno 1 23 error [email protected] lint: eslint . 23 error Exit status 1 24 error Failed at the [email protected] lint script. 24 error This is probably not a problem with npm. There is likely additional logging output above. 25 verbose exit [ 1, true ]

    opened by kangzhongyao 4
  • Manage path with parameters

    Manage path with parameters

    These routes:

    /user/:id
    /user/:id?
    

    should create params object in request

    Example:

    app.get('/user/:firstname?/:lastname', (req, res) => {
      // if we have /user/camel/aissani then
      // req.params.firstname = 'camel'
      // req.params.lastname = 'aissani'
    
      // if we have /user/aissani then
      // req.params.firstname = undefined
      // req.params.lastname = 'aissani'
    });
    
    opened by camelaissani 1
  • HTTP Post/Path request not default handled by frontexpress

    HTTP Post/Path request not default handled by frontexpress

    post and path methods are not completely implemented

    application.httpPost({
        uri: '/users',
        data: { firstname: 'John', lastname: 'Doe'}
    });
    

    The data sent to the server are not default handled by frontexpress. Currently, the user have to implement himself the post patch methods to encode the data sent to the server.

    opened by camelaissani 0
  • Does Service Worker API can be used to listen emitted/received AJAX requests by the application?

    Does Service Worker API can be used to listen emitted/received AJAX requests by the application?

    Currently these methods application.http(Get|Post...)(request, success, failure) are provided to make AJAX calls. Unfortunately, those methods force developers to use a custom API for making AJAX calls rather than using the standard ones (Fetch, XHR).

    May be a solution to avoid this situation is to use the Service Workers? As the SW can play the role of proxy, we can relay on it to listen requests emitted by the application. Thus, the AJAX requests can be invoked from any frameworks (standard JS API, JQuery...) rather than using the ones provided by FrontExpress.

    opened by camelaissani 2
Releases(v1.2.1)
Owner
Camel Aissani
Dad - Full Stack Developer - Code with passion and love
Camel Aissani
A chainable router designed for Next.js api. inspired and regex based from itty-router

Next.js Api Router A chainable router designed for Next.js api. inspired and regex based from itty-router Features Tiny (~8xx bytes compressed) with z

Aris Riswanto 1 Jan 21, 2022
a tiny and isomorphic URL router for JavaScript

Synopsis Director is a router. Routing is the process of determining what code to run when a URL is requested. Motivation A routing library that works

a decoupled application framework 5.6k Dec 28, 2022
A navigation aid (aka, router) for the browser in 850 bytes~!

A navigation aid (aka, router) for the browser in 865 bytes~! Install $ npm install --save navaid Usage const navaid = require('navaid'); // Setup r

Luke Edwards 732 Dec 27, 2022
⚡️The Fullstack React Framework — built on Next.js

The Fullstack React Framework "Zero-API" Data Layer — Built on Next.js — Inspired by Ruby on Rails Read the Documentation “Zero-API” data layer lets y

⚡️Blitz 12.5k Jan 4, 2023
Micro client-side router inspired by the Express router

Tiny Express-inspired client-side router. page('/', index) page('/user/:user', show) page('/user/:user/edit', edit) page('/user/:user/album', album) p

Sloth 7.6k Dec 28, 2022
This is a template project demonstrating how the MERN stack(Mongo, Express, React, Node) can be used, here we have the back end implementation and there is the React implementation as the front end

Versão em português MERN stack This is a template project demonstrating how the MERN stack(Mongo, Express, React, Node) can be used, here we have the

Douglas Samuel Gonçalves 2 Jan 22, 2022
A chainable router designed for Next.js api. inspired and regex based from itty-router

Next.js Api Router A chainable router designed for Next.js api. inspired and regex based from itty-router Features Tiny (~8xx bytes compressed) with z

Aris Riswanto 1 Jan 21, 2022
Router JS 💽 Simple Router building in JavaScript

Router JS ?? Simple Router building in JavaScript

David Montaño Tamayo 1 Feb 12, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
[ON HOLD] Living Style Guides Engine and Maintenance Environment for Front-end Components. Core repository.

[ON HOLD] SourceJS - Living Style Guide Platform The project been stale for a while and currently is in the [ON HOLD] state until we find new maintain

SourceJS 552 Nov 8, 2022
Front end code + minimal express server for mannys.game

mannys-game Front end code + minimal express server for mannys.game. Documentation For full documentation and examples, visit mannys.game/docs. Quick

Manny404 26 Oct 14, 2022
This project was developed to practice Front-end and Back-end comunication, data formatting, http requests GET, POST, DELETE, form validation, it also consumes a rest API

React Application ?? Demonstration of the application | Features | Technologies used | Application installation ?? Demonstration of the application Ap

Victor Lira 36 May 17, 2022
Personal Blog - a project developed with Angular for the front-end interface and Wordpress for the back-end API served with Docker containers

PersonalBlog This project was generated with Angular CLI version 13.0.1. Front-end Interface Development server Run ng serve or ng serve --configurati

null 9 Oct 5, 2022
Pass trust from a front-end Algorand WalletConnect session, to a back-end web service

AlgoAuth Authenticate to a website using only your Algorand wallet Pass trust from a front-end Algorand WalletConnect session, to a back-end web servi

Nullable Labs 16 Dec 15, 2022
It consists of a recreation of Twitter, to put into practice both Front-end and Back-end knowledge by implementing the MERN Stack together with other technologies to add more value to the project.

Twitter-Clone_Back-end ✨ Demo. ?? About the project. ?? Descriptions. It consists of a recreation of Twitter, to put into practice knowledge of both F

Mario Quirós Luna 5 Apr 12, 2022
A super generic Lua web engine. Uses Lua for front-end, JavaScript for back-end, implemented in HTML.

A super generic Lua web engine. Uses Lua for front-end, JavaScript for back-end, implemented in HTML. This project is still in HEAVY development and w

Hunter 2 Jan 31, 2022
It consists of a recreation of Twitter, to put into practice knowledge of both Front-end and Back-end implementing the MERN Stack along with other technologies to add more value to the project.

Twitter-Clone_Front-end ✨ Demo. Login Home Profile Message Notifications Deployed in: https://twitter-clone-front-end.vercel.app/ ?? About the project

Mario Quirós Luna 5 Jun 26, 2022
Web-Technology with Aj Zero Coding. In this tutorial we learn front-end and back-end development.

Installation through NPM: The jQWidgets framework is available as NPM package: jQuery, Javascript, Angular, Vue, React, Web Components: https://www

Ajay Dhangar 3 Nov 19, 2022