Category : koa

I have the following code… const auth = new Authentication(); mainApp.use(auth.checkToken.bind(auth)); mainApp.use(mount(‘/auth’, auth.app)); class Authentication{ constructor() { this.redirectApp = new Koa(); this.redirectApp.use(this.onLogin); this.logoutApp = new Koa(); this.logoutApp.use(this.onLogout); this.callbackApp = new Koa(); this.callbackApp.use(this.onCallback); this.app = new Koa(); this.app.use(mount(‘/login’, this.redirectApp)); this.app.use(mount(‘/callback’, this.callbackApp)); this.app.use(mount(‘/logout’, this.logoutApp)); } checkToken(ctx, next){ if(ctx.path === "/auth/login" || ctx.path === "/auth/callback" || ctx.path === ..

Read more

I just want to return a pdf in response to a GET Request at my Strapi endpoint. Strapi uses Koa, and the Strapi controller atm look as follows: const PDFDocument = require("pdfkit"); module.exports = { async printOne(ctx) { const doc = new PDFDocument(); ctx.set("Content-Type", "application/pdf"); // HTTP response doc.pipe(ctx.res); // add stuff to PDF doc.text("Hello ..

Read more

I was wondering how I can send a response at KOA server after I sent async request and it takes long time (2-3 minutes) for loading the data. router.get(‘/getAllProducts’, async (ctx, next) => { axios.get(‘/data’).then((res) => { ctx.body = res; }); }); If I send a request to /getAllProducts and I am getting 404 error. ..

Read more

I am retrieving data from graphql over koa-server. For that I wrote a function requestData(token, queryName, cursor) to call the graphql. I want to repeat the request until the cursor is null or undefined. I need to use always the last cursor: lastCursor = edges[edges.length – 1].cursor; In the terminal I am getting following outputs: ..

Read more

I use ejs to write the web page. But when i use for will have something wrong code Use for of can work But use for loop will fail I don’t know this different… <% for(post of posts){ %> <div class="layout-card p-5 mb-5"> <h3 class="h3"><%= post.Title %></h3> <div class="text-muted mb-3"><small> <i class="fas fa-calendar-alt mr-2"></i> Create ..

Read more