Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Apr 17 07:51
    Daggy1234 commented #1531
  • Apr 17 07:30
    ranjan-purbey commented #1531
  • Apr 16 18:52
    jkomyno commented #1131
  • Apr 16 18:50
    jkomyno commented #1131
  • Apr 16 18:44
    jkomyno commented #1131
  • Apr 16 18:39
    jkomyno commented #1453
  • Apr 16 18:37
    jkomyno commented #1420
  • Apr 16 18:35
    jkomyno commented #1454
  • Apr 15 17:13
    Daggy1234 opened #1531
  • Apr 15 11:33
    miwnwski closed #1530
  • Apr 15 11:33
    miwnwski commented #1530
  • Apr 15 09:27
    thangly98 commented #1530
  • Apr 15 09:17
    miwnwski labeled #1530
  • Apr 15 09:17
    miwnwski commented #1530
  • Apr 14 09:45
    thangly98 opened #1530
  • Apr 12 12:26
    ryouaki commented #1529
  • Apr 12 12:22
    codecov[bot] commented #1529
  • Apr 12 12:20
    ryouaki synchronize #1529
  • Apr 12 12:14
    ryouaki synchronize #1529
  • Apr 12 12:07
    ryouaki synchronize #1529
Freddy
@fjeddy
Mr Swedish god @jeffijoe, are you alive?
Jeff Hansen
@jeffijoe
@fjeddy I'm danish lol
Freddy
@fjeddy
Sorry, forgot :P
function Property {
  this.something = 'Something'
}

Property.prototype.test = require( './test.js' )

module.exports = Property
That there, the test file will have access to the context right?
As in, this.something will exist in Property.test
But, if I want to do multiple levels, I want to add more files inside the test file so I get Property.test.a and still persist the this context
Jeff Hansen
@jeffijoe
If invoked with the right context, it should, yeah.
Freddy
@fjeddy
Is that possible?
Jeff Hansen
@jeffijoe
I would just not do that.
Freddy
@fjeddy
Why?
The idea is to split one large class file into multiple files
Jeff Hansen
@jeffijoe
I mean you can just iterate those props and bind the funcs in the ctor
What are you trying to achieve?
Freddy
@fjeddy
And because the functions are so large, i would prefer to have one method in one file
My constructor() contains quite a lot of code that is used by almost every single function
So my goal is to split the entire class file into multiple files, but keep the idea of the constructor, and having the data the constructor defined, available in all the sub files
Jeff Hansen
@jeffijoe
Why do you want multiple levels?
Freddy
@fjeddy
Better structure
Keeping one method in one file, as they are rather long
Jeff Hansen
@jeffijoe
Have you considered mixins?
Freddy
@fjeddy
I've looked at it, from what I understood most of them requires a library?
Jeff Hansen
@jeffijoe
Have your sub-files export a function that you call with the prototype
Lol no, module.exports = function testMixin(proto) { proto.test = function() {}; return proto }
Dylan Pierce
@ctrlaltdylan

Just curious on middleware - I'm trying to initialize my mongodb connection in middleware and share it as ctx.db.

When you pass an async function like app.use(async (ctx, next) => { }) does the middleware get resolved before the request is processed?

Jame
@jamemackson
you’ll probably want to initialize your db connection when your app initialized and not in middleware which fire for each connection.
i’d reread the docs about middleware
Dylan Pierce
@ctrlaltdylan
I think I'll have to make a singleton on initialization to represent the database pool and then pass it to the middleware
so it's not reinitializing the db connection on every request
Jame
@jamemackson
that sounds like a solid plan. we’re using TypeORM and thankfully they handle that for us but I believe is their approach as well.
gcnyin
@gcnyin
Hi guys, How do you do distributed trace in koa/express? I found a node.js api AsyncLocationStorage in async_hooks module. I think it's easy to create tracing middleware base on this api. This is my demo repo https://github.com/gcnyin/koa-trace-id. Core part is
const app = new Koa();
const traceIdStorage = new AsyncLocalStorage<string>();

app.use(async (ctx, next) => {
    const traceId = ctx.request.header['x-trace-id'] ?? uuid4()
    traceIdStorage.run(traceId, next)
})

app.use(async ctx => {
    console.log('start', traceIdStorage.getStore())
    await new Promise<void>((resolve) => setTimeout(resolve, 100))
    console.log('end', traceIdStorage.getStore())
    ctx.body = 'Hello World'
})
This is just for application internal. For micro services, you can rewrite http/https modules, and inject traceId in header. These are my thoughts. End.
gcnyin
@gcnyin
Oh, I found cls-rtracer. It already did it.
githubabusebygitter
@githubabusebygitter
When I ctx.throw(), my logger displays the error I throw, but my browser receives a generic 500, Internal Server Error
Something is stealing my Error between the logger (first/last middleware) and the browser
nginx proxy is configured not to intercept errors
any suggestion where to look?
Ivan Jeremic
@ivanjeremic
Hey all. Is there any chance Koa will overtake Express at any time in usage? Why are people so holding on Express?
githubabusebygitter
@githubabusebygitter
@ivanjeremic did three days of silence help answer your question?
Ivan Jeremic
@ivanjeremic
@githubabusebygitter LoL yes, makes no sense to use Koa with this community
Mohammad Hossein Mardani
@mhmardani
hi, guys, I'm node js developer with over 5 years experience and now I'm looking for a development team to join them for work on startups, open-source projects, is anyone here to accept me :)
Davide Pugliese
@Deviad
Hello, I have created a generic function to handle errors,
unfortunately the execution does not stop at the error,
but it keeps going.
https://gist.github.com/Deviad/3b5f9421f791fc5ca790458a57c94e34?fbclid=IwAR1Omdz74gXqI5VcMzx0k5VLi66mlLClZBcTAuTBrarToccErEx9pZ7B9D0#file-handleerrors-ts
What should I do to stop the execution and return an error as I receive it?
Davide Pugliese
@Deviad
Hello
How can I make this work:
app.on('error', (err, ctx) => {
ctx.body = {
data: {
message: err.message,
status: 'error'
}
};
}); ?
1 reply
Jumping Through Hoops
@jumpingthroughhoops_gitlab
how does koa determine mimetype of static files?
Lawrence Wagerfield
@ljwagerfield

Is it possible to automatically retry idempotent requests in Koa?

I've tried writing middleware that does this, but it fails with the following:

next() called multiple times

Would be great to know if there's a way?

Francis Rodrigues
@francisrod01
Hi there. Is there a way to render different template engines by routers in a Koa application?
I'd like to generate some JavaScript files in specific routes, others to render HTML, others JSON.
Douglas Modena
@dmodena

Hello! I'm having trouble with returning the result of an axios post request.

I am able to make the request successfully:

const result = await axios({
      url: 'https://external-api/address',
      mode: 'cors',
      method: 'post',
      data: {
        nome: ctx.request.body.nome,
        email: ctx.request.body.email
      }
    })

I can then log the result:

console.log(result)
---
{ 
  status: 200,
  statusText: 'OK',
  data: 'Your request has been processed!'
}

But I get an error when I try to send this back to the user:

ctx.body = result
---
 TypeError: Converting circular structure to JSON
      --> starting at object with constructor 'ClientRequest'
      |     property 'socket' -> object with constructor 'TLSSocket'
      --- property '_httpMessage' closes the circle

I might be missing something obvious... does anyone know what the error might be?

Douglas Modena
@dmodena

Well, I just figured it out. I can send the status code and message separately, like this:

ctx.status = response.status
ctx.body = response.data

I am just not sure why I cannot send the whole response JSON as the body, but that's okay.