Koa router show 404 even though breakpoint hit and response received successfully
I want to send a get request(use axios) to koa router, but from vscode debug view,
router ctx.status
always show 404
, and ctx.message show "Not Found"
But my request finished perfect..
I want to query mongodb base type
, so I register two routers tag
,post
if type===post
, we call next()
and let tag router
to process it
Here are my codes
export default function (this: server) {
queryPost(this.router, this)
queryTag(this.router, this)
}
/**
* type=post&path=postpath
* @param router
*/
async function queryPost(router: Router, server: server) {
router.get('/api/blog', async (ctx, next) => {
let query = ctx.query
let type = query.type
if (type !== 'post') {
return next()
}
let path = query.path
let config = server.config
ctx.body = await server.mgController.query(config.postsCollectionName, {
path: path
})
})
}
/**
* type=tag&name=tagsname
* @param router
*/
async function queryTag(router: Router, server: server) {
let config = server.config
router.get('/api/blog', async (ctx, next) => {
let query = ctx.query
let type = query.type
if (type !== 'tag') {
return next()
}
let name = query.name
ctx.body = await server.mgController.query(config.postsCollectionName, {
'matter.tags':[name]
}, {
sort: {
originDate: 1
},
projection: {
title: 1,
path: 1,
excerpt: 1,
'matter.tags':1,
originDate: 1,
updatedDate: 1
} as TagQueryExcerpt
} as FindOneOptions)
})
}
koa koa-router
add a comment |
I want to send a get request(use axios) to koa router, but from vscode debug view,
router ctx.status
always show 404
, and ctx.message show "Not Found"
But my request finished perfect..
I want to query mongodb base type
, so I register two routers tag
,post
if type===post
, we call next()
and let tag router
to process it
Here are my codes
export default function (this: server) {
queryPost(this.router, this)
queryTag(this.router, this)
}
/**
* type=post&path=postpath
* @param router
*/
async function queryPost(router: Router, server: server) {
router.get('/api/blog', async (ctx, next) => {
let query = ctx.query
let type = query.type
if (type !== 'post') {
return next()
}
let path = query.path
let config = server.config
ctx.body = await server.mgController.query(config.postsCollectionName, {
path: path
})
})
}
/**
* type=tag&name=tagsname
* @param router
*/
async function queryTag(router: Router, server: server) {
let config = server.config
router.get('/api/blog', async (ctx, next) => {
let query = ctx.query
let type = query.type
if (type !== 'tag') {
return next()
}
let name = query.name
ctx.body = await server.mgController.query(config.postsCollectionName, {
'matter.tags':[name]
}, {
sort: {
originDate: 1
},
projection: {
title: 1,
path: 1,
excerpt: 1,
'matter.tags':1,
originDate: 1,
updatedDate: 1
} as TagQueryExcerpt
} as FindOneOptions)
})
}
koa koa-router
Defaultctx.status
is 404,and it will be 200 afterctx.body=something
without giving a specific status code. See github.com/koajs/koa/blob/master/lib/response.js#L134
– lx1412
Dec 20 '18 at 3:16
add a comment |
I want to send a get request(use axios) to koa router, but from vscode debug view,
router ctx.status
always show 404
, and ctx.message show "Not Found"
But my request finished perfect..
I want to query mongodb base type
, so I register two routers tag
,post
if type===post
, we call next()
and let tag router
to process it
Here are my codes
export default function (this: server) {
queryPost(this.router, this)
queryTag(this.router, this)
}
/**
* type=post&path=postpath
* @param router
*/
async function queryPost(router: Router, server: server) {
router.get('/api/blog', async (ctx, next) => {
let query = ctx.query
let type = query.type
if (type !== 'post') {
return next()
}
let path = query.path
let config = server.config
ctx.body = await server.mgController.query(config.postsCollectionName, {
path: path
})
})
}
/**
* type=tag&name=tagsname
* @param router
*/
async function queryTag(router: Router, server: server) {
let config = server.config
router.get('/api/blog', async (ctx, next) => {
let query = ctx.query
let type = query.type
if (type !== 'tag') {
return next()
}
let name = query.name
ctx.body = await server.mgController.query(config.postsCollectionName, {
'matter.tags':[name]
}, {
sort: {
originDate: 1
},
projection: {
title: 1,
path: 1,
excerpt: 1,
'matter.tags':1,
originDate: 1,
updatedDate: 1
} as TagQueryExcerpt
} as FindOneOptions)
})
}
koa koa-router
I want to send a get request(use axios) to koa router, but from vscode debug view,
router ctx.status
always show 404
, and ctx.message show "Not Found"
But my request finished perfect..
I want to query mongodb base type
, so I register two routers tag
,post
if type===post
, we call next()
and let tag router
to process it
Here are my codes
export default function (this: server) {
queryPost(this.router, this)
queryTag(this.router, this)
}
/**
* type=post&path=postpath
* @param router
*/
async function queryPost(router: Router, server: server) {
router.get('/api/blog', async (ctx, next) => {
let query = ctx.query
let type = query.type
if (type !== 'post') {
return next()
}
let path = query.path
let config = server.config
ctx.body = await server.mgController.query(config.postsCollectionName, {
path: path
})
})
}
/**
* type=tag&name=tagsname
* @param router
*/
async function queryTag(router: Router, server: server) {
let config = server.config
router.get('/api/blog', async (ctx, next) => {
let query = ctx.query
let type = query.type
if (type !== 'tag') {
return next()
}
let name = query.name
ctx.body = await server.mgController.query(config.postsCollectionName, {
'matter.tags':[name]
}, {
sort: {
originDate: 1
},
projection: {
title: 1,
path: 1,
excerpt: 1,
'matter.tags':1,
originDate: 1,
updatedDate: 1
} as TagQueryExcerpt
} as FindOneOptions)
})
}
koa koa-router
koa koa-router
asked Nov 25 '18 at 12:29
toffeetoffee
581110
581110
Defaultctx.status
is 404,and it will be 200 afterctx.body=something
without giving a specific status code. See github.com/koajs/koa/blob/master/lib/response.js#L134
– lx1412
Dec 20 '18 at 3:16
add a comment |
Defaultctx.status
is 404,and it will be 200 afterctx.body=something
without giving a specific status code. See github.com/koajs/koa/blob/master/lib/response.js#L134
– lx1412
Dec 20 '18 at 3:16
Default
ctx.status
is 404,and it will be 200 after ctx.body=something
without giving a specific status code. See github.com/koajs/koa/blob/master/lib/response.js#L134– lx1412
Dec 20 '18 at 3:16
Default
ctx.status
is 404,and it will be 200 after ctx.body=something
without giving a specific status code. See github.com/koajs/koa/blob/master/lib/response.js#L134– lx1412
Dec 20 '18 at 3:16
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467445%2fkoa-router-show-404-even-though-breakpoint-hit-and-response-received-successfull%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467445%2fkoa-router-show-404-even-though-breakpoint-hit-and-response-received-successfull%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Default
ctx.status
is 404,and it will be 200 afterctx.body=something
without giving a specific status code. See github.com/koajs/koa/blob/master/lib/response.js#L134– lx1412
Dec 20 '18 at 3:16