Skip to content

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"}]%
@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

3 participants