Server is running fine when it is on development. But when you build the typescript and try to run index.js inside the dist folder after installing necessary dependency. It will no longer find the models.
To Reproduce
Steps to reproduce the behavior:
Run tsc
Go to dist folder
Copy package.json inside dist folder
Run npm i to install dependecy
Wait for the server to connect to database
Make a request. Any request will do.
Error will popup on terminal.
Expected behavior
Models will be found just like on development in typescript.
When deploying the transpiled code from ts to js and deploy it to AWS Elastic Beanstalk. It will show at the logs that the modules for the models are not found.
To Reproduce
Steps to reproduce the behavior:
Build you app.
Deploy it to your provider whether DigitalOcean or AWS.
To cater more developers and users. We need to have a feature to handle multiple databases. Right now mayajs can only handles one database at a time. We need to be able to handle an array of database that can be added on the app.module.ts. This can be only implemented if we can handle external module.
π Todo:
database param on app.module.ts handles array
Create a Database interface for outside modules
Create a database handler and database switcher
π Additional Info
This feature is vital for the release of version 1.0.0.
To handle multiple database we must have a universal model decorator. This decorator creates an objects that maps all the fields and exposes and API for the Database class to consume. This way we will just write one model and it can be used by any database.
Maya class will accepts the AppModule and bootstrap all the necessary routes and models if any. It also serves as an instance of Express.app. It's also responsible for starting and setting up the server and listens to it.
π Todo:
Create Maya class
Create bootstrap function
Create start function
Create use function This function is for using global middleware that all the routes will use.
It will hard to everyone to use this library if they don't have any sample project that they can start of. We can make a simple project that utilize the basic usage of this library. Like how to make a simple folder structure and simple controller example.
π Todo:
Create a sample project folder.
Create an index.ts
Create a controller.ts
Create a app.module.ts
π Additional Info
This sample project is a basic implementation of this library.
Models decorator accepts a name of a model related to a controller. This will replace the value of the variable it was decorated to the value of the model that has the same name that pass on it. This a collection of models and bootstrapped alongside with all the controllers.
Sample code
@Models()const model : Model<any,any>;
π Todo:
Create Models decorator
Create an object of models
Map all the model and add it on the model object when bootstrapping
Models decorator must replace the value of the variable with the correct model name
Models can be called on anywhere not only inside the controller
π Additional Info
This decorator must only work if there is a model defined on the @Controller() decorator.
Right now MayaJS is using express.js as a routing library under the hood. But this is not bad for us to use it but in the future it is better to have our own routing module for us to scale more. I suggest we need to create a routing library for @mayajs/core.
Updates
Already publish mayajs/router on npm. I will update @mayajs/core to use this library and remove express as dependency.
βοΈ Component
@mayajs/routing
π Todo:
Create a routing library
Routing must be able to plug over app.module.ts
Routing must be able to have middlewares like express does
Routing can handle all types of HTTP METHODS
Routing can have a default validator (OPTIONAL)
Routing can have a default response handler (OPTIONAL)
π Additional Info
This feature is vital for the release of version 1.0.0.
I saw the greetings.yml file under .github >> workflow directory, is that a typo error?
**greetings.yml **
name: Greetingson: [pull_request, issues]jobs:
greeting:
runs-on: ubuntu-lateststeps:
- uses: actions/first-interaction@v1with:
repo-token: ${{ secrets.GITHUB_TOKEN }}issue-message: 'Thank you for creating your first issue. Keep collaborating!!!'' first issue'pr-message: 'Thank you for creating your first PR. We will review it shortly.'' first pr'
App module will be the one to accepts all the server settings. It will use the App decorator that decorates all the settings on it. App decorator will accept a settings object. All the settings are list below.
Sample AppModule class decorated with App and accepts settings options interface.
@App({cors?: boolean;// Enable CORS default falselogs?: string;// Enable logging OPTIONAL// Connect to MongoDB OPTIONALmongoConnection?: {url: string;// Connection stringoptions?: ConnectionOptions|undefined;// Mongoose connect options OPTIONAL};// Port number where the server will listenport: number;// Default 3333// List of routes with controllers and middlewaresroutes: Array<{callback?: Function;// This call function will be called lastcontrollers: Controller[];// List of Controllersmiddlewares: Function[];// Middlewares for all the routes i.e. JWT Authenticationpath: string;// Main path of this route}>;})exportclassAppModule{};
NOTE:
Middlewares on the routes array applied for all the controllers. If you want to apply a middleware for a specific route. You can define it on the validations option of the METHOD DECORATOR.
Method decorator middleware example:
@Post({path: "/",validations: [/* middlewares for specific route */],})
π Todo:
Create App Decorator
Add optional CORS
Add mongoose for MongoDB connection
Add express for creating server to use in background
Add morgan for optional logging
π Additional Info
For SQL connection and other database type it will be added on the future. For now we are just focusing on MongoDB.
There's a little bit confusion on what validations really are on the Method Decorators. For clarity sake can we rename it to just middlewares. Middlewares can be also considered as validations.