|
@@ -7,7 +7,7 @@ import { |
|
|
ServerParams, |
|
|
ServerParams, |
|
|
} from '../../../backend'; |
|
|
} from '../../../backend'; |
|
|
import http from 'http'; |
|
|
import http from 'http'; |
|
|
import { constants } from 'http2'; |
|
|
|
|
|
|
|
|
import { statusCodes } from '../../../common'; |
|
|
|
|
|
|
|
|
declare module '../../../backend' { |
|
|
declare module '../../../backend' { |
|
|
interface ServerRequest extends http.IncomingMessage {} |
|
|
interface ServerRequest extends http.IncomingMessage {} |
|
@@ -26,12 +26,12 @@ class ServerInstance<Backend extends BaseBackend> implements Server<Backend> { |
|
|
private readonly requestListener = async (req: ServerRequest, res: ServerResponse) => { |
|
|
private readonly requestListener = async (req: ServerRequest, res: ServerResponse) => { |
|
|
// const endpoints = this.backend.app.endpoints; |
|
|
// const endpoints = this.backend.app.endpoints; |
|
|
if (typeof req.method === 'undefined') { |
|
|
if (typeof req.method === 'undefined') { |
|
|
res.writeHead(constants.HTTP_STATUS_BAD_REQUEST, {}); |
|
|
|
|
|
|
|
|
res.writeHead(statusCodes.HTTP_STATUS_BAD_REQUEST, {}); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
if (typeof req.url === 'undefined') { |
|
|
if (typeof req.url === 'undefined') { |
|
|
res.writeHead(constants.HTTP_STATUS_BAD_REQUEST, {}); |
|
|
|
|
|
|
|
|
res.writeHead(statusCodes.HTTP_STATUS_BAD_REQUEST, {}); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
@@ -44,7 +44,7 @@ class ServerInstance<Backend extends BaseBackend> implements Server<Backend> { |
|
|
.find((op) => op.method === req.method?.toUpperCase()); |
|
|
.find((op) => op.method === req.method?.toUpperCase()); |
|
|
|
|
|
|
|
|
if (typeof foundAppOperation === 'undefined') { |
|
|
if (typeof foundAppOperation === 'undefined') { |
|
|
res.writeHead(constants.HTTP_STATUS_METHOD_NOT_ALLOWED, { |
|
|
|
|
|
|
|
|
res.writeHead(statusCodes.HTTP_STATUS_METHOD_NOT_ALLOWED, { |
|
|
'Allow': appOperations.map((op) => op.method).join(',') |
|
|
'Allow': appOperations.map((op) => op.method).join(',') |
|
|
}); |
|
|
}); |
|
|
res.end(); |
|
|
res.end(); |
|
@@ -53,7 +53,7 @@ class ServerInstance<Backend extends BaseBackend> implements Server<Backend> { |
|
|
|
|
|
|
|
|
const endpointOperations = Array.from(endpoint?.operations ?? []); |
|
|
const endpointOperations = Array.from(endpoint?.operations ?? []); |
|
|
if (!endpointOperations.includes(foundAppOperation.name)) { |
|
|
if (!endpointOperations.includes(foundAppOperation.name)) { |
|
|
res.writeHead(constants.HTTP_STATUS_METHOD_NOT_ALLOWED, { |
|
|
|
|
|
|
|
|
res.writeHead(statusCodes.HTTP_STATUS_METHOD_NOT_ALLOWED, { |
|
|
'Allow': endpointOperations |
|
|
'Allow': endpointOperations |
|
|
.map((a) => appOperations.find((aa) => aa.name === a)?.method) |
|
|
.map((a) => appOperations.find((aa) => aa.name === a)?.method) |
|
|
.join(',') |
|
|
.join(',') |
|
@@ -64,13 +64,13 @@ class ServerInstance<Backend extends BaseBackend> implements Server<Backend> { |
|
|
|
|
|
|
|
|
const implementation = this.backend.implementations.get(foundAppOperation.name); |
|
|
const implementation = this.backend.implementations.get(foundAppOperation.name); |
|
|
if (typeof implementation === 'undefined') { |
|
|
if (typeof implementation === 'undefined') { |
|
|
res.writeHead(constants.HTTP_STATUS_NOT_IMPLEMENTED); |
|
|
|
|
|
|
|
|
res.writeHead(statusCodes.HTTP_STATUS_NOT_IMPLEMENTED); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (typeof endpoint === 'undefined') { |
|
|
if (typeof endpoint === 'undefined') { |
|
|
res.writeHead(constants.HTTP_STATUS_NOT_IMPLEMENTED); |
|
|
|
|
|
|
|
|
res.writeHead(statusCodes.HTTP_STATUS_NOT_IMPLEMENTED); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
@@ -88,7 +88,7 @@ class ServerInstance<Backend extends BaseBackend> implements Server<Backend> { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
if (typeof responseSpec === 'undefined') { |
|
|
if (typeof responseSpec === 'undefined') { |
|
|
res.writeHead(constants.HTTP_STATUS_UNPROCESSABLE_ENTITY, {}); |
|
|
|
|
|
|
|
|
res.writeHead(statusCodes.HTTP_STATUS_UNPROCESSABLE_ENTITY, {}); |
|
|
res.end(); |
|
|
res.end(); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|