Skip to content

fix status 404 when use with koa-connect #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sorrycc
Copy link

@sorrycc sorrycc commented Jan 23, 2016

I have used json-server with koa, and the problem is, statusCode is always 404.

server.js

var koa = require("koa");
var route = require("koa-route");
var express = require("express");
var server = express();
var c2k = require("koa-connect");
var jsonServer = require("json-server");

server.use("/api", jsonServer.router('json-server.json'));

app = koa();
app.use(c2k(server));
app.listen(3000);

test with curl

$ curl -i http://localhost:3000/api/posts
HTTP/1.1 404 Not Found
X-Powered-By: Express
X-Content-Type-Options: nosniff
Content-Type: application/json; charset=utf-8
Content-Length: 51
ETag: W/"33-gAAIDPXQFEM2+C2ZOklPIQ"
Date: Sat, 23 Jan 2016 01:01:25 GMT
Connection: keep-alive

[{"id":1,"content":"foo"},{"id":2,"content":"bar"}]%

@xmlking
Copy link

xmlking commented Mar 15, 2017

same issue for me
https://github.com/xmlking/hub/blob/master/server/src/index.ts

@fritx
Copy link

fritx commented Nov 5, 2022

Any progress on this?

I have to server.use('/prefix', ...) for each call to make it work with path prefix:

server.use('/prefix', middlewares)
server.use('/prefix', (req, res, next) => {/* ... */})
server.use('/prefix', router)
koaApp.use(koaConnect(server))

instead of just:

let koaRouter = new KoaRouter({ prefix: '/prefix' })
koaRouter.use(server)
koaApp.use(koaRouter)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants