camelaissani / frontexpress Goto Github PK
View Code? Open in Web Editor NEWAn Express.js-Style router for the front-end
Home Page: https://frontexpressjs.com
License: MIT License
An Express.js-Style router for the front-end
Home Page: https://frontexpressjs.com
License: MIT License
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!
Please also publish this on bower. Greatly appreciated, thank you!
normal file size, minified, gzipped?
Also is there a cdn, so people who aren't using bower could include it?
I'm not sure what is wrong, when i click on the anchors tags i get a 404 error, with the root path executes the innerHTML instruction.
This is my code
https://gist.github.com/aldebaran798/c1762a669d3719d70b37c7ea726d1ca7
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]prelint: no script for prelint, continuing
6 silly lifecycle [email protected]
7 info lifecycle [email protected]lint: [email protected]lint: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]
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_perllint: CWD: E:\test\frontexpress
10 verbose lifecycle [email protected]
11 silly lifecycle [email protected]lint: Args: [ '/d /s /c', 'eslint .' ]lint: Returned: code: 1 signal: null
12 silly lifecycle [email protected]
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 ]
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
Can it work in ie9
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.
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'
});
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.
Currently, requests are sent through the XMLHttpRequest object.
Simplify and make the code more standard by using Fetch API.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.