GithubHelp home page GithubHelp logo

javieraviles / node-typescript-koa-rest Goto Github PK

View Code? Open in Web Editor NEW
992.0 22.0 172.0 1.35 MB

REST API boilerplate using NodeJS and KOA2, typescript. Logging and JWT as middlewares. TypeORM with class-validator, SQL CRUD. Docker included. Swagger docs, actions CI and valuable README

Home Page: https://node-typescript-koa-rest.herokuapp.com/swagger-html

License: MIT License

TypeScript 89.46% Dockerfile 0.95% Python 8.18% Shell 1.41%
node koa koa2 typescript rest-api koa-router koa-jwt winston nodemon docker

node-typescript-koa-rest's People

Contributors

dependabot[bot] avatar ejose19 avatar javieraviles avatar mberneti avatar oryxfea avatar rpaezbas avatar steve-a-jones avatar

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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-typescript-koa-rest's Issues

Loading the configuration file

I noticed that in the server.ts file is the configuration read after import.

import * as dotenv from 'dotenv';
import { config } from './config';
// Load environment variables from .env file, where API keys and passwords are configured
dotenv.config({ path: '.env' });

Shouldn't it be the opposite?

import * as dotenv from 'dotenv';
// Load environment variables from .env file, where API keys and passwords are configured
dotenv.config({ path: '.env' });
import { config } from './config';

Feedback: This project kicks ass.

Hey @javieraviles

I just wanted to say thanks for this. Of all the "generators / templates" out there that I have used this is by far the best. Very lightweight and has excellent functionality - a perfect starter kit.

The only thing I had trouble with was winston as #38 . Whenever you are throwing an error it never gets to log (regardless if you set the file path). I switched it out with koa-bunyan-logger and it's far more usable.

The one and ONLY thing I would consider adding to the main repo is AJV for validating the request https://www.npmjs.com/package/ajv . I didn't need AJV for this particular project but I will look into sending a future PR with AJV validation in TypeScript (if you are interested).

Other than that, I hope you keep it lightweight.

Anyone looking at this a potential starter for your next rest project, I highly recommend it.

Anyways, thanks!

[Question] repository

Hello,

In your structure that can create specific repository in directory repository(for exemple) adn for exemple do a finction like :

@EntityRepository(Evaluation)
export class EvaluationRepository extends Repository<Evaluation> {
    public getListDatesEvaluation(
        beneficiaireId: number
    ): Promise<Evaluation[] | undefined> {
        return this.createQueryBuilder('evaluation')
            .select()
            .leftJoinAndSelect('evaluation.usagers', 'usagers')
            .where('usagers.id IN (:beneficiaireId)', {
                beneficiaireId,
            })
            .orderBy('evaluation.dateEvaluation', 'DESC')
            .getMany();
    }
}

Thanks

start npm run watch-server error (fresh install)

Hello,

I clone, install and run npm run watch-server got this error :

var eventName = msg.name === 'error' ? 'errorMessage' : msg.name
                          ^
TypeError: Cannot read property 'name' of undefined

Thanks

watch-server doesn't work on windows 10

in my addition, nodemon can't monitor src folder code change.
unless i edit the script code
"watch-server": "nodemon --watch src -e ts,tsx --exec ts-node src/server.ts",

this works!

Swagger is blocked by CSP

When I visit http://localhost:3000/swagger-html, I got below error in the console.

Refused to load the script 'https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.21.0/swagger-ui-bundle.js' because it violates the following Content Security Policy directive: "script-src 'self'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

It turns out that the Content Security Policy enabled by helmet blocks loading swagger related files from CDN, since this issue is gone after comment out app.use(helmet()).

after I run the program,I have not 'swagger-html' ?

First,very thank you publish this project for us,it's help me a lot .I write a project myself based on your project,thank you so much!
but now, i have a question:
afterI run this project,and the server have successd running on port 9000 , but I have no 'swagger-html':

import { request, summary, query } from 'koa-swagger-decorator';
 @request('get', '/searchTangPoetry')
    @summary('搜索唐诗的接口')
    @query({
        author: { type: 'string', required: true, default: DEFAULT_SEARCH_POETRY, description: '作者名字' },
    })

image

Hope to receive your help ,thank you again!!

why second request Throw out Error: write after end In `watch-server`

  Error: write after end
      at writeAfterEnd (D:\Code\Github\demo-ts\node_modules\readable-stream\lib\_stream_writable.js:288:12)
      at PassThrough.Writable.write (D:\Code\Github\demo-ts\node_modules\readable-stream\lib\_stream_writable.js:332:20)
      at File.log (D:\Code\Github\demo-ts\node_modules\winston\lib\winston\transports\file.js:158:34)
      at File._write (D:\Code\Github\demo-ts\node_modules\winston-transport\index.js:81:19)
      at doWrite (D:\Code\Github\demo-ts\node_modules\readable-stream\lib\_stream_writable.js:428:64)
      at writeOrBuffer (D:\Code\Github\demo-ts\node_modules\readable-stream\lib\_stream_writable.js:417:5)
      at File.Writable.write (D:\Code\Github\demo-ts\node_modules\readable-stream\lib\_stream_writable.js:334:11)
      at DerivedLogger.ondata (D:\Code\Github\demo-ts\node_modules\readable-stream\lib\_stream_readable.js:619:20)
      at emitOne (events.js:121:20)
      at DerivedLogger.emit (events.js:211:7)

I only open the db logger

createConnection({
    type: 'postgres',
    host: connectionOptions.host,
    port: connectionOptions.port,
    username: connectionOptions.user,
    password: connectionOptions.password,
    database: connectionOptions.database,
    synchronize: true,
    logging: false,
    entities: [
       'dist/entity/**/*.js'
    ],
    extra: {
        ssl: config.dbsslconn, // if not development, will use SSL
    }
 })

How to initialize the database?

When GET /users, throw error RepositoryNotFoundError: No repository for "User" was found. Looks like this entity is not registered in current "default" connection?

Tests Structure Request

Hi, this is an amazing boilerplate project and i'd like to say thanks for this; i'd like to suggest a basic implementation to make use of a testing library. It could be great with that.

Need more infor on jwt.io

This is an awesome project. Thank you so much for getting this out.

I find it very helpful and I started using it for a personal project that I'm heavily involved with the API related work.

I noticed that this should have more helpful information when using the jwt.io when generating the token for integration testing and API testing.

I can create a PR if you are ok with that. Please let me know.

npm run start throws an error

I'm not sure what I'm doing wrong but when I running it for production:

npm run build
npm start

I get the following error:

TypeORM connection error:  /home/yev/Laboratory/koa/koa-typescript/src/entity/user.ts:1
import { Entity, Column, PrimaryGeneratedColumn } from "typeorm";
       ^

SyntaxError: Unexpected token {

is this a typescript issue?

Run migrations

hi, thanks for the boilerplate,
how i can create the database for this?

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.