-
How to get url? from template in koa2
my page uses the views layouts index.hbs template, in which there are three links corresponding to three pages. The question now is: how can I get the current path, because I want to set the active class name to the corresponding link according to t...
-
Is the middleware Synchronize in the koa2 framework or asynchronous?
question 1: why is the middleware in the koa2 framework written in the form of async, rarely in Synchronize mode (that is, without async)? For example,
app.use(async (ctx, next) => {
const start = new Date()
await next()
const ms = new Date() ...
-
Koa interface cross-domain error report
several interfaces are written with koa+mongodb. Cross-domain errors are always reported when requesting with ajax, even if cors is used in koa. Google has done a lot of things but still hasn t solved the problem .
const cors = require( koa2-cors );
...
-
Ctx.body cannot receive content in koa2
ctx.body = await service.get_search_data(start,count,keyword,(err,res)=>{
if(err){
return ;
}else {
return res;
}
}
)
The res in the callback function can accept the data, so why can t the ctx.body accept it? ...
-
What is the function of the front and rear end separation koa2?
for example, the front and rear separation project vue + axios + koa2 + java (springboot) uses restful style api question:
what role does koa2 play? Specifically, what code should be written in koa2?
Under the vue+koa2 front-end combination, where...
-
How to set the koa download file to "utf-8"
ctx.set( Content-disposition , attachment; filename=district.csv );
ctx.set( content-type , text csv; charset=utf-8 );
ctx.statusCode = 200;
ctx.body = csv;
set excel to open or garbled in this way
...
-
How to learn Node? systematically
I would like to ask you bosses about the problems in the direction of learning
how to learn Node has always been my doubt. The blogs and tutorials I read on the Internet are all about learning several core modules of Nodejs (fs,path,event,buffer,http)...
-
Koa2 queries the result object of the database and adds new attributes, but the front end cannot get it asynchronously.
1. First of all, get the order list through the query, and then add the user name and user password for each order object through the for loop. When I console.log, the console has output, but when I, ctx.body = {data:orderList}, the result obtained asyn...
-
Frontend vue axios backend koa2, frontend sends requests without cookie
the subject has just learned node and back-end knowledge. There was a problem when combining the previous todolist written in vue with the back-end code (login section).
Front end Code-vue methods
methods: {
checkHasLogin () {
axios.get( ...
-
Webpack + koa A message waiting to be packaged wait until bundle finished:
require( babel-register )
const express = require( express )
const webpack = require( webpack )
const webpackConfig = require( . webpack.config )
const app = express()
webpack
var compiler = webpack(webpackConfig);
webpack-dev-server
var ...
-
How does koa implement MVC?
router.get( meibrain , async (ctx, next) => {
await ctx.render( meibrain , {
imgSrc: images newsbannenr.png ,
koa-router
})
})...
-
Koa2 uses mongodb to write api interface to get data, how to get data elegantly (I am adding data to a new object, it's too low)
const MongoClient = require( mongodb ).MongoClient;
const url = mongodb: localhost:27017 ;
Database Name
const dbName = youyue ;
var obj = {};
module.exports = async(ctx,next)=>{
const num = ctx.query.num,
page = ctx.query.pag...
-
Node server rendered page, a tag opens the URL of this page will report 400, invalid request
RT Route is: koa-router A parameter is handwritten in the browser address bar, which can be obtained by the server. It is written on the a tag but reported 400 ....
-
Koa-router usage problems!
how to get controllers frontListNewsCenter.js data in router.get ( ) of routes news.js
routes news.js
const router = require( koa-router )({
prefix: news
})
const config = require( .. config )
const controllers = require...
-
The development of koa2 web is confused and asks for advice.
I fumbled to do web development with koa2, and now I find that the front desk is unable to request data. I would like to ask what is unreasonable?
controllers
page.js
models
pageModel.js
public
routes
index.js
views
page.ejs
app.j...
-
Koa2 server rendering web development, how to deal with the data interaction triggered by browser events?
how to deal with it generally, all I can think of is to do some interfaces on the node server, as shown in the following figure:
routes news.js
const router = require( koa-router )({
prefix: news
})
const config = require( .. config )
...
-
How does koa2 manage api routing and page routing
how does RT:koa2 manage api routing and page routing? ...
-
Is it good to have two koa programs on the same server, one for interface and one for server rendering?
is it necessary for RT: to do this?
if you don t think this is necessary, how can koa-router standardize the interface path and html path?
...
-
Does the ctx.render () load page need to wait for all subsequent execution to be completed before the final result is displayed?
the business you want to achieve is to render the page first, and then add content to the page through ctx.body
the core code is as follows
await ctx.render( crawler , {
title: ,
content: `<h2>< h2>
<h4>...
-
What's the difference between koa2's ctx.state ctx.body?
is there any difference below?
controllers
async function get (ctx, next) {
const res = await models.test.get()
ctx.state.data = res.data
******* ********
ctx.body = res.data
await next()
}
module.exports = {
ge...