stellar-deprecated / stex Goto Github PK
View Code? Open in Web Editor NEWDEPRECATED. An opinionated framework built on top of expressjs used to build better web services for stellar
License: Other
DEPRECATED. An opinionated framework built on top of expressjs used to build better web services for stellar
License: Other
tl;dr; We should both standardize the directory layout of stex for both "model" and "controller" files and automatically load them at stex initialization
Problem
The CommonJS model for adding module dependencies is nice for being explicit about inter-module dependencies and has overall led to much better javascript code. However, it can lead to very large sections of "require" blocks at the top of each file that can distract from the function of the module, and more importantly it leaves each module the freedom to name the symbols that it imports, leading to naming inconsistencies:
// in module 1:
var wallet = require('wallet');
// in module 2:
var Wallet = require('wallet');
Furthermore, within a single node project you are forced to use relative requires, leading to friction when you restructure your project or rename a file:
// when in a sibling module
var wallet = require("./wallet")
// when in a child module
var wallet = require("../wallet")
Proposal
There exists a set of modules within a stex application that are used quite often throughout nearly all the other modules in a stex application: the "models" and the "controllers". By automatically loading these files we will reduce duplication and increase clarity. I propose we automatically load files underneath /lib/controllers and /lib/models. For example, the routes file (app.js) could go from this:
var walletsCtrl = require("./controllers/wallets")
var totpCtrl = require("./controllers/totp")
var recoverCtrl = require("./controllers/recovery")
router.post("/v2/wallets/create", walletsCtrl.create);
router.post("/v2/wallets/update", walletsCtrl.update);
router.post("/v2/totp/enable", totpCtrl.enable);
// etc.
to:
router.post("/v2/wallets/create", stex.controllers.wallets.create)
router.post("/v2/wallets/update", stex.controllers.wallets.update)
router.post("/v2/totp/enable", stex.controllers.totp.enable);
// etc.
https://github.com/Unitech/pm2 is pretty badass. Lets see if we can leverage it in the context of stex.
When a stex application recieves a request, it would be nice to attach a unique id to every log that arrises from that request. that way logs could be tracked by request id. the asynchronous nature of node makes this hard as you lose context in the callback after the event loop.
here's a potential solution or model we could use https://datahero.com/blog/2014/05/22/node-js-preserving-data-across-async-callbacks/
Ideally most of the functionality would be abstracted into Stex, and all the client would need to do is add some stex speicific middleware to their request chain, and any further call to Stex.log will automatically add that request id to the log.
is it possible to use remote authenticated redis DB's with stex? error is:
Error: Ready check failed: NOAUTH Authentication required.
Stex is not yet published on the public npm repository. Would it be possible to add it ?
It's come to my attention that in stellar-api we're forwarding any call to stex.error.log
to sentry. This is not a good situation. It means that error reports in stellar-api are actually just log lines that alias most of the useful information encoded into a Error
object. It seems that this solution was chosen because we did not have defined with stex a reusable system to report errors.
We should add this functionality at stex.reportError
which should behave similar to the stex errors middleware: It logs as well as reports to sentry as peer operations, not dependent ones. From the code:
var reportErrorDirectly = function(err) {
log.error(err.message);
// report to sentry if we are enabled
if(sentry) {
sentry.captureError(err);
}
};
I propose we extract that functionality to a method stex.reportError
, such that the above code becomes:
var reportErrorDirectly = function(err) {
stex.reportError(err);
};
Similar to the rails initializer system, the stex initializer system will allow applications to define custom "startup" and "shutdown" functions as well as a dependency mechanism to allow code inside an initializer to leverage other portions of the framework
Use url-pattern instead of minimatch for domain matching.
https://github.com/snd/url-pattern#match-domains
Currently, a stex service looks like it is running, even if every worker process immediately dies.
We should build a generator for http://yeoman.io/ that will bootstrap a new stex-based project.
If a connection is killed by mysql, or the running stex application otherwise gets its connection into a fatal state, stex does not properly recover and the service requires a restart to resume normal function.
Instead, stex needs to validate/reconnect to the db at the HTTP request boundary if no connection is available, and we need to close connections after we receive a fatal error.
As a developer building an application on top of stex, I would like to be able to easily defined multiple entrypoints for my application, so that I can build one-time processes, cron-based repeated jobs, or multiple web service APIs on top of one codebase
Presently, there are only 2 types of processes that can be started on top of stex... the www
process started via stex run www
and the repl process started via stex console
. The goal of this issue is to unify how we launch processes within stex as well as enable an application to define their own entrypoints.
For example, you may have a custom job queue running process that you want run within the stex ecosystem (giving access to the db,log,conf globals). Or you may have written a database cleaning process to resolve some prior corruption.
The following paragraph describes a possible design:
Every stex application has a top-level folder called scripts. By default, it is populated with 2 files: www.js, and console.js. These two scripts can be launched with either stex run www
or stex run console
respectively.
A script launched in this manner (via stex run NAME
) will execute after having the stex ecosystem loaded and initialized.
A developer can define additional scripts simply by creating new files within the scripts folder, which can then be run as expected by executing stex run
. In this way, stex run NAME
is just an alias for:
node scripts/NAME.js
.
Previous discussion: stellar/stellar-api#54
Current one looks bad in Travis.
See 01df521#commitcomment-8995392 for context. I would just change it, but don't have stuff set up for local testing yet, so filing it for now.
As a developer running in a stex console process, I want to be able to execute javascript that returns a promise which is then resolved before printing, so that I can have a more friendly asynchronous experience when using the REPL.
Presently, the stex repl process is very bare-bones... simply using the built in node 'repl' module with no customization. Given that most of the useful code in node is asynchronous (and for stex, promise-based), the repl is quite hard to use because you pretty much end up having to write lines like: db("wallets").where("id", id).select().then(console.log)
This is a pain and slows down the explorative experience of a repl, IMO. It would nicer instead if we built a repl that saw the return value of a statement was a Promise, resolve it, then printout the value for the developer... essentially automating the .then(console.log)
part.
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.