Coder Social home page Coder Social logo

kitesjs / kites Goto Github PK

View Code? Open in Web Editor NEW
54.0 54.0 6.0 1.65 MB

Template-based Web Application Framework

Home Page: https://kitesjs.github.io/kites

License: MIT License

TypeScript 97.13% JavaScript 1.94% HTML 0.93%
autodiscover extensions-manager javascript-framework kites kites-templates kitesjs lightweight-framework nodejs-framework template-based typescript-framework web-application-framework websockets

kites's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

kites's Issues

Add HttpContext

The HttpContext property allow us to access the current request, response and user with ease.

  • Access HttpContext in controllers derived from BaseHttpController or @Inject decorator.

Support end to end testing

When the application grows, it is hard to manually test a behavior of each API endpoint. The end-to-end tests help us to make sure that everything is working correctly and fits project requirements.

TODO:

  • Add new module @kites/testing to support end to end testing
  • Help to init or close application properly
  • Support override kites providers and extensions usage

Example:

import { KitesInstance } from '@kites/core';
import { Test } from '@kites/testing';

import * as request from 'supertest';
import { TodoController } from './todo.controller';
import { TodoService } from './todo.service';

describe('Todo e2e', () => {
  let app: KitesInstance;
  let todoService = { findAll: () => ['list all tasks'] };

  beforeAll(async () => {
    app = await Test.createApp({
      providers: [TodoService],
    }).init();
  });

  it(`/GET list`, () => {
    return request(app.express.app)
      .get('/api/todo')
      .expect(200)
      .expect({
        data: todoService.findAll(),
      });
  });

  afterAll(async () => {
    await app.close();
  });
});

Add api close

  • add new api close to close kites application
  • may be use combine events with rxjs

Example:

// close application
await kites.close();

Add api discover

Add new api .discover(boolean | [{path, level, ...options}]) to discover extension in directory tree

Options:

  • boolean: turn on discover mode with default options, search in all folders has kites.config.js in kites.options.appPath
  • options: objects with multiple paths configuration
import {engine} from '@kites/core';

async function bootstrap() {
  // let kites autodiscover the extensions
  const app = await engine().discover(true).init();
  app.logger.info('A new kites started!');
}

bootstrap();

OR

import {engine} from '@kites/core';

async function bootstrap() {
  // let kites autodiscover the extensions
  const app = await engine().discover([true, 2, '/path1', '/path2']).init();
  app.logger.info('A new kites started!');
}

bootstrap();

Implement http action results

List action results.

  • OkResult
  • OkNegotiatedContentResult
  • RedirectResult
  • ResponseMessageResult
  • StatusCodeResult
  • BadRequestErrorMessageResult
  • BadRequestResult
  • ConflictResult
  • CreatedNegotiatedContentResult
  • ExceptionResult
  • InternalServerError
  • NotFoundResult
  • JsonResult

Example:

@Controller("/todo")
class ToDoController extends BaseApiController {
    @Get("/:task")
    public async info() {
        return this.ok("foo");
    }

    @Get("/")
    public async list() {
        const content = { foo: "bar" };
        const statusCode = 403;

        return this.json(content, statusCode);
    }

Implement DI System

Trying to implement DI System for Kites.

Example:

Extension({
  controllers: [],
  views: []
})
class TodoExtension {
  constructor(@Inject(TodoService) svTodo: TodoService,) {
    // callable injected service here
    this.svTodo.begin(task);
  }
}

Inject KITES_INSTANCE

  • Allow KITES_INSTANCE can be injected into Controllers, Services

Example:

import {Injectable, Inject} from '@kites/common';
import {KITES_INSTANCE, KitesInstance} from '@kites/core';

@Injectable()
class TodoService {
  constructor(
    @Inject(KITES_INSTANCE ) private kites: KitesInstance,
  ) {
    this.kites.logger.info('Injected kites instance!!');
  }
}

Kites Micro Frontend

Build admin panel as an extension of kites. #kites-admin

First implement will use React?

Extensions have own their controllers and views for micro frontend.

Example:

Extension({
  prefix: 'api/v1',   // api route prefix
  controllers: [
    `./controllers/todo.controller`,
    `./controllers/user.controller`,
  ],
  views: [
    `./pages/user`,
    `./pages/dashboard`
  ]
})
class TodoExtension {}

Output:

  • The application publish the API controllers.
  • The client can access two generated pages: User and Dashboard

Todo - Kites Extensions/Templates

Wanted the list of cli tools:

  • mvc: Assembling all into complete ship (default), document
  • basic: Template for building from scratch
  • apidoc: Template for API Documentation, nodevn/kites-apidoc
  • express: Template for Express Application
  • restful: Template for generating a RESTful API Server
  • spa: Template for generating a Single Page Application (kites/spa)
  • cms: Template for generating a Content Management System (CMS)
  • chat: Template for generating a Chat application
  • chatbot: Template for generating an AI Chatbot application, vntk/chatbot, document
  • videocall: Template for generating a Video Call application
  • electron: Template for creating a desktop application with native_modules
  • gateway: Template for creating a microservices API Gateway
  • oauth|oauth2: Template for creating an OAuth2 Server
  • crawler: Template for crawl news, products, ...

Syntax:

kites init [my_app_name] --template chatbot

Example:

kites init my_kute_chatbot --template chatbot

Then a new project will be generated at the current directory.

Add BaseApiController

  • Allow a new controller definition extends from BaseApiController

Example:

@Controller("/")
class ExampleController extends BaseApiController {
    @Get("/")
    public async info() {
        return this.ok("foo");
    }

fs discover permission not allowed

Stat file folder without permission then we got an error:

2019-10-01T00:04:26.461Z [kites] info: Initializing [email protected] in mode "development", using configuration file kites.config.json
2019-10-01T00:04:26.470Z [kites] info: Searching for available extensions in E:\Projects\roomrtc\roomrtc-ce
2019-10-01T00:04:26.475Z [kites] info: Skipping extensions location cache when NODE_ENV=development or when option extensionsLocationCache === false, crawling now!
(node:8828) UnhandledPromiseRejectionWarning: Error: UNKNOWN: unknown error, stat 'E:\Projects\roomrtc\roomrtc-ce\node_modules\.bin\clang-apply-replacements'
    at Object.statSync (fs.js:855:3)
    at readFiles (E:\Projects\roomrtc\roomrtc-ce\node_modules\@kites\core\extensions\fs.js:113:24)
    at readFiles (E:\Projects\roomrtc\roomrtc-ce\node_modules\@kites\core\extensions\fs.js:115:38)
    at readFiles (E:\Projects\roomrtc\roomrtc-ce\node_modules\@kites\core\extensions\fs.js:115:38)
    at Object.walkSyncLevel (E:\Projects\roomrtc\roomrtc-ce\node_modules\@kites\core\extensions\fs.js:128:36)
    at Object.get (E:\Projects\roomrtc\roomrtc-ce\node_modules\@kites\core\extensions\location-cache.js:22:21)
    at Object.discover (E:\Projects\roomrtc\roomrtc-ce\node_modules\@kites\core\extensions\discover.js:26:35)
    at ExtensionsManager.init (E:\Projects\roomrtc\roomrtc-ce\node_modules\@kites\core\extensions\extensions-manager.js:75:47)
    at KitesInstance.init (E:\Projects\roomrtc\roomrtc-ce\node_modules\@kites\core\engine\kites-instance.js:179:38)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:832:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.