GithubHelp home page GithubHelp logo

koa-es7-boilerplate's People

Contributors

brendanvinson avatar crobinson42 avatar iraycd avatar jakobrosenberg avatar jeffijoe 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

koa-es7-boilerplate's Issues

Use new ECMAScript modules

I would like to remove the babel dependency and use the new ECMAScript modules support but it seems like a hard task.

What I did:

  1. I added "type": "module" in the package.json.
  2. I added .js for every file import. An example:
import { logger } from './logger'

into:

import { logger } from './logger.js'
  1. For every file that use __dirname variable I added this code:
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

like suggested here: https://nodejs.org/api/esm.html#esm_no_require_exports_module_exports_filename_dirname

  1. For the awilix-router-core npm module I tried to use import like suggested here: jeffijoe/awilix-router-core#6
  2. I got stuck on an error related to require in the awilix npm module (https://github.com/jeffijoe/awilix/blob/master/src/container.ts#L584) and now I don't know what to do.

Can someone help me about that?

How can we access one service function in another service class

Hi Joe,

Greetings of the day...!!!

We have created some generic service and we would like call the another service class function in this service.

and all services are registered under loaded under scoped.

When we are trying to loadthe service in the constructor function and using the same in our function getting below error.

→ TypeError: Cannot read property 'apply' of undefined
→ at memberInvoker (D:\UI\Projects\koa-abs\node_modules\awilix-koa\src\invokers.ts:93:38)
→ at dispatch (D:\UI\Projects\koa-abs\node_modules\koa-router\node_modules\koa-compose\index.js:44:32)
→ at next (D:\UI\Projects\koa-abs\node_modules\koa-router\node_modules\koa-compose\index.js:45:18)
→ at D:\UI\Projects\koa-abs\node_modules\koa-router\lib\router.js:346:16
→ at dispatch (D:\UI\Projects\koa-abs\node_modules\koa-router\node_modules\koa-compose\index.js:44:32)
→ at D:\UI\Projects\koa-abs\node_modules\koa-router\node_modules\koa-compose\index.js:36:12
→ at dispatch (D:\UI\Projects\koa-abs\node_modules\koa-router\lib\router.js:351:31)
→ at dispatch (D:\UI\Projects\koa-abs\node_modules\koa-compose\index.js:42:32)
→ at D:\UI\Projects\koa-abs\node_modules\koa-compose\index.js:34:12
→ at dispatch (D:\UI\Projects\koa-abs\node_modules\koa-compose\index.js:42:32)
→ at scopePerRequestMiddleware (D:\UI\Projects\koa-abs\node_modules\awilix-koa\src\scope-per-request.ts:13:12)
→ at dispatch (D:\UI\Projects\koa-abs\node_modules\koa-compose\index.js:42:32)
→ at bodyParser (D:\UI\Projects\koa-abs\node_modules\koa-bodyparser\index.js:86:11)
→ at
→ at process._tickDomainCallback (internal/process/next_tick.js:228:7)

Could you please provide any help in this regard.

remove stage 1

node js support native async await after v7.4 better koa performance

API Documentation

I really liked the work done in the project, Its definitely one of the most interesting boilerplates out there. Unfortunately, there is a major draw back - which is lack of documentation. Not project documentation, but auto generated API documentation, something like Swagger, apidoc etc.

So my request is simple, if possible, please advise on how to integrate a tool like Swagger.
Thanks!

Consider using babel-preset-env instead of specific year preset

I've switched to using babel-preset-env and have it set up so it auto-detects what version of node I'm running and transpiles the code based on that.

It feels easier and more dynamic than having to gauge what version of node supports what version of ecmascript and at what stage.

example .babelrc:

{
    "presets": [
        ["env", {
            "targets": {
                "node": "current"
            }
        }]
    ]
}

nodemon multiple times when changes

Hello,

I have an issue with the current configuration when running "npm run dev"

sometimes when i save, i get multiple times:
[nodemon] restarting due to changes...
[nodemon] starting npm run babel-node src/bin/server.js

which causes issues, sometimes it crash as the app continue to runs on the same port.. then i got an exception "already running on port 1338"

I don't have any clue how to fix that, it's difficult to work on the project as each time i save I need to find the process by pid and kill it.

lsof -i tcp:1338
to find the process.

If you have any ideas.

Kr,

An automatic line change Function

Hi, I use your boilerplate.

When I was commit, source code lines change automatic.

ex)
image

I want to my code line T. T

package.json File.
image
image

help me~

How can i use my stores as classes

I'm applying TypeScript to my code and using this boilerplate as reference. When i run the app i get this error message:

    →  TSError: ⨯ Unable to compile TypeScript:
    →  src/services/user-service.ts(2,10): error TS2305: Module '"../stores/user-store"' has no exported member 'UserStore'.
    →  
    →      at createTSError (/home/damasceno/dev/forum-api/node_modules/ts-node/src/index.ts:230:12)
    →      at getOutput (/home/damasceno/dev/forum-api/node_modules/ts-node/src/index.ts:336:40)
    →      at Object.compile (/home/damasceno/dev/forum-api/node_modules/ts-node/src/index.ts:369:11)
    →      at Module.m._compile (/home/damasceno/dev/forum-api/node_modules/ts-node/src/index.ts:415:43)
    →      at Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    →      at Object.require.extensions.(anonymous function) [as .ts] (/home/damasceno/dev/forum-api/node_modules/ts-node/src/index.ts:418:12)
    →      at Module.load (internal/modules/cjs/loader.js:599:32)
    →      at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    →      at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    →      at Module.require (internal/modules/cjs/loader.js:637:17)
    →      at require (internal/modules/cjs/helpers.js:22:18)
    →      at Object._loadModulesDeps.require (/home/damasceno/dev/forum-api/node_modules/awilix/src/container.ts:553:18)
    →      at modules.map.m (/home/damasceno/dev/forum-api/node_modules/awilix/src/load-modules.ts:100:33)
    →      at Array.map (<anonymous>)
    →      at Object.loadModules (/home/damasceno/dev/forum-api/node_modules/awilix/src/load-modules.ts:92:26)
    →      at Object.loadModules (/home/damasceno/dev/forum-api/node_modules/awilix/src/container.ts:558:5)

This is my user-store.ts:

import UserSchema, { User } from '../models/user-model';

export default class UserStore {
  logger: any;

  constructor(logger: any) {
    this.logger = logger;
  }

  async find() {
    this.logger.debug('Getting all users');
    return await UserSchema.find();
  }

  async findOneById(id: String) {
    this.logger.debug(`Getting user with id ${id}`);
    return await UserSchema.findById(id);
  }

  async create(user: User) {
    this.logger.debug(`Creating user with id ${user.id}`);
    return await new UserSchema(user).save();
  }

  async update(id: String, user: User) {
    this.logger.debug(`Updating user with id ${id}`);
    return await UserSchema.findByIdAndUpdate(id, user, { new: true });
  }

  async remove(id: String) {
    this.logger.debug(`Removing user with id ${id}`);
    return UserSchema.findByIdAndRemove(id);
  }
}

And this is my container.ts

import { Lifetime, InjectionMode, createContainer, asValue, AwilixContainer } from 'awilix';
import { logger } from './logger';

const modulesToLoad: any = [
  ['services/*.ts', Lifetime.SCOPED],
  ['stores/*.ts', Lifetime.SINGLETON]
];

/**
 * @returns {AwilixContainer} The container
 */
export function configureContainer(): AwilixContainer {
  const options: any = {
    injectionMode: InjectionMode.CLASSIC
  };
  return createContainer(options)
    .loadModules(modulesToLoad, {
      cwd: `${__dirname}/..`,
      formatName: 'camelCase'
    })
    .register({
      logger: asValue(logger)
    });
}

You can see the complete code here forum-api

Can I get more examples?

I think your boilerplate is awesome!!.
But, I want to know the details and principles of your code.

Purpose of invoker/invocation?

Hi,

Sorry to bother you, but still a bit unclear on the purpose of the invocation.js/invoker methods. I understand its for the AwilixContainer object where it will all resolve (i think?), but in the context of this template, do we simply reuse the one given to us? Or does (typically) require a a new one to be created for each service or api we make?

Upgrade koa-cors, remove koa-convert

As of koa-cors 2.x it's compatible with Koa 2, so we no longer need to include koa-convert. Also, can set Koa to require straight 2.0.0 instead of 2.0.0-alpha.

Where to write import statements from node modules?

Hi,
It wasn't really clearly stated, but if I wanted to import other node modules, would I put it in the lib/createServer.js or whatever service file I make (ie. services/myWhateverService.js)? If it's for a database connections or something used globally, would it be better to import it in the former?

Trouble when deploy to heroku

Hi, I have used this boilerplate to build 2 apis and love it so much. However, I am not able to deploy to heroku. It returns this error all the time.

capture

I did try to install source-map or source-map/register by using Heroku's console but it does not work. My deploy method is using GitHub and I already push the folder "dist" to GitHub but doesn't change anything.

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.