alex-levacher / lumie Goto Github PK
View Code? Open in Web Editor NEW✨ An opinionated way to keep your express API organized
License: MIT License
✨ An opinionated way to keep your express API organized
License: MIT License
I could not find anything about this in the documentation so I'm guessing this is not thought of yet.
So I have my /api/
path which is the "root", and then I wanted to listen to a parameter right after like this: /api/:project
. To create this you could prefix the filename with an underscore.
The naming structure would be _project-get.js
Which would generate:
public get /api/:project
Could this be something to implement, or is this already possible?
EDIT**
I noticed that you could name it project.routing.js
and it would give you the result I wanted. But I think it creates confusion of where the action is placed since its in a routing named file. Best way to solve this solution?
I saw level access triggers before middlewares.
How i can attach current user on api call, an then call the permission middleware using the level?
Hi everyone,
I'm looking for new ideas to promote Lumie. If you have some, don't hesitate to list them below.
I'll share with you the results of the different suggested actions by updating this post with the statistics.
Thanks ✌🏼
Hi, I think you can remove express js as dependency or declared as peer dependency. Don't you think ?
Express validator doesn't work as intended.
routing.js:
const post = require("./post.action")
module.exports = {
'/': {
post: {
action: post.createUser,
middlewares: post.middlewares,
level: 'public'
}
}
}
action.js:
const { body } = require('express-validator/check');
/**
* Middlewares
*/
module.exports.middlewares = [
body('email', 'Invalid email').isEmail(),
body('password', 'username invalid').exists()
]
module.exports.createUser = (req, res) => {
// Get triggered even if 'email' and 'password' body's fields are empty/not valid
res.status(201).send("test")
}
But, if I do this:
module.exports.middlewares = [
(req, res, next) => {
console.log("Middleware is working!")
next()
}
]
The middleware get triggered as expected
for example in the img below it should be 'cars' not 'car', same for 'user' it should be 'users'
https://raw.githubusercontent.com/Alex-Levacher/Lumie/master/images/preview-run.png
Thank you for your job!
How should I use passport authenticate function with lumie?
This is my original route:
router.get(
"/discord/callback",
passport.authenticate("discord"),
(req, res) => res.redirect("/")
);
The converted function that doesn't work:
const callback = (req, res) => {
passport.authenticate("discord");
res.redirect("/");
};
module.exports = {
"/discord/callback": {
get: {
action: callback,
level: "public"
}
}
};
First, I just wanna say, I love Lumie, really great work.
I m a bit confused with the permissions. I want member
to go through my JWT express middleware. Could you add an example of how to do this?
I don't want to add middleware on each route, I just want set level to member and it should be handled by itself. Is this possible?
A controller with an async
function that throws an error, that error doesn't reach the error handler middleware.
module.exports.getAll = async (req, res) => {
throw new Error('async error');
};
const express = require('express');
const Lumie = require('lumie');
const app = express();
Lumie.load(app, {
verbose: process.env.NODE_ENV !== 'test',
preURL: 'api',
ignore: ['*.spec', '*.action'],
controllers_path: path.join(__dirname, '../api/controllers')
});
//error handler middleware
app.use((err, req, res, next) => {
return res.status(500).json({ message: 'error' });
});
module.exports = app;
(node:3690) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:3690) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Use a function to wrap the controller action that resolve the promise, in case of error, catch that and pass it to next middleware
https://stackoverflow.com/questions/51391080/handling-errors-in-express-async-middleware
Every controller defines his own route over own name, for example:
controllers/project.js
[Project]
public get [/project/]
member get [/project/number/:value]
project-ctrl.js
module.exports = {
'/': {
get: {
action: index,
level: 'public'
}
},
...
This creates a path for listen over project/. If do i want to listen over root path?
For example:
preURL
is /
./
without another parameter, specific controllers over this clean path. Is It neccesary do it outside Lumie config?It would be interesting being able to programmatically access the detected routes, e.g the data used to generate this:
> node index.js
======== ROUTES ========
[Battery]
public get [/api/battery/]
[Consumption]
public get [/api/consumption/]
[Production]
public get [/api/production/]
public get [/api/production/solar]
public get [/api/production/wind]
========================
Example app listening at http://127.0.0.1:3000
It would allow automatic API discovery and -why not- the creation of a client SDK
So I inherited a project that is using lumie but the webpack/babel production builds do not work. Ended up tracing down the error to a path resolution issue with Lumie when it tries to load the controller paths but I'm not sure how to handle this (part of the problem is definitely my very limited knowledge of webpack/bable configs).
Has anybody successfully configured webpack builds for a lumie/express app? Any examples or just general idea on how to configure this properly would be greatly appreciated (sorry I know this is pretty vague, really just looking for where to get started and I can do my own research from there).
Thanks for any help!
can't seem to find a type definition for this library , is there one available by chance ?
https://github.com/Alex-Levacher/Lumie/blob/master/src/index.js#L62
If the preURL
is not set in options, the error is thrown.
path.js:28
throw new TypeError('Path must be a string. Received ' + inspect(path));
^
TypeError: Path must be a string. Received undefined
Don't know if it's a bug or not.
If you use single quotes on preUrl lumie don't recognize the option only with double quotes
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.