How can I mount a solid server with nextjs, node, and solid library?

Viewed 793

I'm new to nextjs and node-solid-server. I have a simple application with node and nextjs. In my api/solid rout of my application, I'm trying to add a solid server as a middleware like this:

const Ldnode = require('ldnode')
const Solid = require('solid-server')
import initMiddleware from '../../lib/init-middleware'

// Initialize the cors middleware
const solid = initMiddleware(
  Solid()

)

export default async function handler(req, res) {
  // Run solid
  await solid(req, res)

  // Rest of the API logic
  res.json({ message: 'Hello Everyone!' })
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

export default function initMiddleware(middleware) {
  return (req, res) =>
    new Promise((resolve, reject) => {
      middleware(req, res, (result) => {
        if (result instanceof Error) {
          return reject(result)
        }
        return resolve(result)
      })
    })
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
However, when I enter http://localhost:3000/api/solid in my browser, I just have the index.html of solid server with no functionality as the image below:

I also got GET http://localhost:3000/api/solid 401 (Unauthenticated) and GET http://localhost:3000/common/css/bootstrap.min.css net::ERR_ABORTED 404 (Not Found).

Did I miss something?

1 Answers

node-solid-server is a monolith that can either be used as a standalone express server or as a library which lets you mount it in an existing express server. On the other hand, nextjs api routes run on a serverless function implementation. While you can't mount node-solid-server in your api route like that, you could run it standalone and make requests to it from your nextjs app.

Related