koa2

    0熱度

    1回答

    我正在編寫一個完整的堆棧應用程序,在節點js中使用koa框架作爲後端,角點4作爲前端。問題是,當我通過前端在後端API上發佈post請求時(即,當我想登錄時),我得到一個帶有「發生網絡錯誤」文本和代碼19的DOM異常。後端本身工作正常用郵差測試它)。這裏是我的角碼的片段,其中包括我提出請求的服務方法和處理響應的組件方法。 服務方法: authenticate(username: string, p

    1熱度

    1回答

    有沒有任何理由爲什麼Koa被執行兩次每個請求? const Koa = require('koa') const app = new Koa() const index = async(ctx, next) => { console.log('Hello world!') await next() ctx.body = 'Hello world!' } a

    0熱度

    1回答

    這就是我在想的,僞代碼。 const myRedirect = (routePath) => { newUrl = routePath; if (matches condition) newUrl = do_some_modification(routePath); return next(newUrl); } const myFunc = (ro

    0熱度

    1回答

    我想如何將中間件應用到koa-route的所有路徑,例如 router1.use((ctx) => { console.error("hello 0 ..."); console.log(ctx.url); } router1.all((ctx) => { console.error("hello 0 ..."); console.log(ctx.url

    0熱度

    1回答

    我想從我的Koa 2中間件中獲取var值以顯示在我的pug模板(或其他)中。 例如,在KOA的會話我: app.use(ctx => { // ignore favicon if (ctx.path === '/favicon.ico') return; let n = ctx.session.views || 0; ctx.session.views =

    1熱度

    1回答

    使用koa2ejskoa-router,ejs template如何使用其他中間件的ctx.state 本地主機:3000 /管理/ usermsg admin.get('/usermsg', async(ctx) => { ctx.state.userMsg = { page: Number(ctx.query.page), limit: 4,

    0熱度

    1回答

    我不太明白如何捕捉我扔的地方深我的路線裏面的錯誤,例如: // put router.put('/', async (ctx, next) => { let body = ctx.request.body || {} if (body._id === undefined) { // Throw the error. ctx.throw(400, '_id

    4熱度

    1回答

    有沒有人與koa.js和流一起工作? 考慮這個例子 const fs = require('fs'); const Koa = require('koa'); const app = new Koa(); app.use(async (ctx) => { ctx.body = fs.createReadStream('really-large-file'); }); ap

    0熱度

    1回答

    我正在使用koa-passport進行身份驗證,憑據存儲在mySQL服務器上。每個用戶名在數據庫表中都有一個唯一的ID。我正在使用一個非常簡單的方案,我只是將ID用於序列化和反序列化,而不是具有整個用戶對象。 對於身份驗證,數據庫中定義了一個存儲過程,如果在數據庫中爲所提供的憑據(數據庫中存儲過程同時查看用戶名和密碼,因此不需要在nodeJS上處理)返回null或userID。此外,假設下面的代碼

    0熱度

    1回答

    我已經KOA app和玩笑測試框架,app包裹由http.createServer並連接到蒙戈 mongooseConnect(); const app = new Koa(); initHandlers(app); app.use(routes); export default http.createServer(app.callback()); 測試supertest不關閉