swagger-express-middleware icon indicating copy to clipboard operation
swagger-express-middleware copied to clipboard

ERR_HTTP_INVALID_STATUS_CODE

Open nieben opened this issue 2 years ago • 0 comments

Hello,

I create a simple server with code:

/**************************************************************************************************
 * This sample demonstrates the most simplistic usage of Swagger Express Middleware.
 * It simply creates a new Express Application and adds all of the Swagger middleware
 * without changing any options, and without adding any custom middleware.
 **************************************************************************************************/
'use strict';

const createMiddleware = require('@apidevtools/swagger-express-middleware');
const path = require('path');
const express = require('express');

// Create an Express app
const app = express();

// Initialize Swagger Express Middleware with our Swagger file
let swaggerFile = path.join(__dirname, 'swagger.yaml');
createMiddleware(swaggerFile, app, (err, middleware) => {

    // Add all the Swagger Express Middleware, or just the ones you need.
    // NOTE: Some of these accept optional options (omitted here for brevity)
    app.use(
        middleware.metadata(),
        middleware.CORS(),
        middleware.files(),
        middleware.parseRequest(),
        middleware.validateRequest(),
        middleware.mock()
    );

    // Start the app
    app.listen(8000, () => {
        console.log('The Swagger Pet Store is now running at http://localhost:8000');
    });
});

The server started successfully, bu when i visit http://localhost:8000/, i got error output in console:

node:_http_server:297
    throw new ERR_HTTP_INVALID_STATUS_CODE(originalStatusCode);
    ^

RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: NaN
    at new NodeError (node:internal/errors:387:5)
    at ServerResponse.writeHead (node:_http_server:297:11)
    at ServerResponse._implicitHeader (node:_http_server:288:8)
    at write_ (node:_http_outgoing:826:9)
    at ServerResponse.end (node:_http_outgoing:934:5)
    at write (...\swagger-server\node_modules\finalhandler\index.js:302:9)
    at AsyncResource.runInAsyncScope (node:async_hooks:203:9)
    at listener (...swagger-server\\node_modules\on-finished\index.js:170:15)
    at onFinish (...\swagger-server\node_modules\on-finished\index.js:101:5)
    at callback (...\swagger-server\node_modules\ee-first\index.js:55:10) {
  code: 'ERR_HTTP_INVALID_STATUS_CODE'
}

what is the reason? Thanks. Env: windows 10, node v16.17.0

nieben avatar Oct 10 '22 09:10 nieben