|
@@ -38,9 +38,9 @@ export const handleGetRoot: Middleware = ({ |
|
|
appState, |
|
|
appState, |
|
|
appParams, |
|
|
appParams, |
|
|
serverParams, |
|
|
serverParams, |
|
|
responseBodyMediaType: [responseBodyMediaType, responseBodySerializerPair], |
|
|
|
|
|
|
|
|
responseBodyMediaType, |
|
|
responseBodyLanguage, |
|
|
responseBodyLanguage, |
|
|
responseBodyEncoding: [encodingKey, encoding], |
|
|
|
|
|
|
|
|
responseBodyEncoding, |
|
|
errorResponseBodyLanguage, |
|
|
errorResponseBodyLanguage, |
|
|
}) => (_req: IncomingMessage, res: ServerResponse) => { |
|
|
}) => (_req: IncomingMessage, res: ServerResponse) => { |
|
|
const data = { |
|
|
const data = { |
|
@@ -49,7 +49,7 @@ export const handleGetRoot: Middleware = ({ |
|
|
|
|
|
|
|
|
let serialized; |
|
|
let serialized; |
|
|
try { |
|
|
try { |
|
|
serialized = responseBodySerializerPair.serialize(data); |
|
|
|
|
|
|
|
|
serialized = responseBodyMediaType.serialize(data); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
@@ -63,7 +63,7 @@ export const handleGetRoot: Middleware = ({ |
|
|
|
|
|
|
|
|
let encoded; |
|
|
let encoded; |
|
|
try { |
|
|
try { |
|
|
encoded = encoding.encode(serialized); |
|
|
|
|
|
|
|
|
encoded = responseBodyEncoding.encode(serialized); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
@@ -76,9 +76,9 @@ export const handleGetRoot: Middleware = ({ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const theHeaders: Record<string, string> = { |
|
|
const theHeaders: Record<string, string> = { |
|
|
'Content-Type': responseBodyMediaType, |
|
|
|
|
|
|
|
|
'Content-Type': responseBodyMediaType.name, |
|
|
'Content-Language': responseBodyLanguage.name, |
|
|
'Content-Language': responseBodyLanguage.name, |
|
|
'Content-Encoding': encodingKey, |
|
|
|
|
|
|
|
|
'Content-Encoding': responseBodyEncoding.name, |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const registeredResources = Array.from(appState.resources); |
|
|
const registeredResources = Array.from(appState.resources); |
|
@@ -107,9 +107,9 @@ export const handleGetRoot: Middleware = ({ |
|
|
|
|
|
|
|
|
export const handleGetCollection: Middleware = ({ |
|
|
export const handleGetCollection: Middleware = ({ |
|
|
resource, |
|
|
resource, |
|
|
responseBodyMediaType: [responseBodyMediaType, responseBodySerializerPair], |
|
|
|
|
|
|
|
|
responseBodyMediaType, |
|
|
responseBodyLanguage, |
|
|
responseBodyLanguage, |
|
|
responseBodyEncoding: [encodingKey, encoding], |
|
|
|
|
|
|
|
|
responseBodyEncoding, |
|
|
errorResponseBodyLanguage, |
|
|
errorResponseBodyLanguage, |
|
|
backendState, |
|
|
backendState, |
|
|
query, |
|
|
query, |
|
@@ -148,7 +148,7 @@ export const handleGetCollection: Middleware = ({ |
|
|
|
|
|
|
|
|
let serialized; |
|
|
let serialized; |
|
|
try { |
|
|
try { |
|
|
serialized = responseBodySerializerPair.serialize(data); |
|
|
|
|
|
|
|
|
serialized = responseBodyMediaType.serialize(data); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
@@ -162,7 +162,7 @@ export const handleGetCollection: Middleware = ({ |
|
|
|
|
|
|
|
|
let encoded; |
|
|
let encoded; |
|
|
try { |
|
|
try { |
|
|
encoded = encoding.encode(serialized); |
|
|
|
|
|
|
|
|
encoded = responseBodyEncoding.encode(serialized); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
@@ -175,9 +175,9 @@ export const handleGetCollection: Middleware = ({ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const headers: Record<string, string> = { |
|
|
const headers: Record<string, string> = { |
|
|
'Content-Type': responseBodyMediaType, |
|
|
|
|
|
|
|
|
'Content-Type': responseBodyMediaType.name, |
|
|
'Content-Language': responseBodyLanguage.name, |
|
|
'Content-Language': responseBodyLanguage.name, |
|
|
'Content-Encoding': encodingKey, |
|
|
|
|
|
|
|
|
'Content-Encoding': responseBodyEncoding.name, |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
if (typeof totalItemCount !== 'undefined') { |
|
|
if (typeof totalItemCount !== 'undefined') { |
|
@@ -195,9 +195,9 @@ export const handleGetCollection: Middleware = ({ |
|
|
export const handleGetItem: Middleware = ({ |
|
|
export const handleGetItem: Middleware = ({ |
|
|
resourceId, |
|
|
resourceId, |
|
|
resource, |
|
|
resource, |
|
|
responseBodyMediaType: [responseBodyMediaType, responseBodySerializerPair], |
|
|
|
|
|
|
|
|
responseBodyMediaType, |
|
|
responseBodyLanguage, |
|
|
responseBodyLanguage, |
|
|
responseBodyEncoding: [encodingKey, encoding], |
|
|
|
|
|
|
|
|
responseBodyEncoding, |
|
|
errorResponseBodyLanguage, |
|
|
errorResponseBodyLanguage, |
|
|
}) => async (_req: IncomingMessage, res: ServerResponse) => { |
|
|
}) => async (_req: IncomingMessage, res: ServerResponse) => { |
|
|
try { |
|
|
try { |
|
@@ -229,7 +229,7 @@ export const handleGetItem: Middleware = ({ |
|
|
|
|
|
|
|
|
let serialized: string | null; |
|
|
let serialized: string | null; |
|
|
try { |
|
|
try { |
|
|
serialized = data === null ? null : responseBodySerializerPair.serialize(data); |
|
|
|
|
|
|
|
|
serialized = data === null ? null : responseBodyMediaType.serialize(data); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
@@ -243,7 +243,7 @@ export const handleGetItem: Middleware = ({ |
|
|
|
|
|
|
|
|
let encoded; |
|
|
let encoded; |
|
|
try { |
|
|
try { |
|
|
encoded = serialized === null ? null : encoding.encode(serialized); |
|
|
|
|
|
|
|
|
encoded = serialized === null ? null : responseBodyEncoding.encode(serialized); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
@@ -257,9 +257,9 @@ export const handleGetItem: Middleware = ({ |
|
|
|
|
|
|
|
|
if (encoded) { |
|
|
if (encoded) { |
|
|
res.writeHead(constants.HTTP_STATUS_OK, { |
|
|
res.writeHead(constants.HTTP_STATUS_OK, { |
|
|
'Content-Type': responseBodyMediaType, |
|
|
|
|
|
|
|
|
'Content-Type': responseBodyMediaType.name, |
|
|
'Content-Language': responseBodyLanguage.name, |
|
|
'Content-Language': responseBodyLanguage.name, |
|
|
'Content-Encoding': encodingKey, |
|
|
|
|
|
|
|
|
'Content-Encoding': responseBodyEncoding.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = responseBodyLanguage.statusMessages.resourceFetched(resource) |
|
|
res.statusMessage = responseBodyLanguage.statusMessages.resourceFetched(resource) |
|
|
res.end(encoded); |
|
|
res.end(encoded); |
|
@@ -353,12 +353,12 @@ export const handlePatchItem: Middleware = ({ |
|
|
appState, |
|
|
appState, |
|
|
resource, |
|
|
resource, |
|
|
resourceId, |
|
|
resourceId, |
|
|
responseBodyMediaType: [responseBodyMediaType, responseBodySerializerPair], |
|
|
|
|
|
|
|
|
responseBodyMediaType, |
|
|
responseBodyLanguage, |
|
|
responseBodyLanguage, |
|
|
responseBodyEncoding: [encodingKey, encoding], |
|
|
|
|
|
|
|
|
responseBodyEncoding, |
|
|
errorResponseBodyLanguage, |
|
|
errorResponseBodyLanguage, |
|
|
errorResponseBodyMediaType: [errorMediaType, errorSerializerPair], |
|
|
|
|
|
errorResponseBodyEncoding: [errorEncodingKey, errorEncoding], |
|
|
|
|
|
|
|
|
errorResponseBodyMediaType, |
|
|
|
|
|
errorResponseBodyEncoding, |
|
|
}) => async (req: IncomingMessage, res: ServerResponse) => { |
|
|
}) => async (req: IncomingMessage, res: ServerResponse) => { |
|
|
const { deserializerPair: requestBodyDeserializerPair, encodingPair: requestBodyEncodingPair } = getDeserializerObjects(appState, req); |
|
|
const { deserializerPair: requestBodyDeserializerPair, encodingPair: requestBodyEncodingPair } = getDeserializerObjects(appState, req); |
|
|
if (typeof requestBodyDeserializerPair === 'undefined' || typeof requestBodyEncodingPair === 'undefined') { |
|
|
if (typeof requestBodyDeserializerPair === 'undefined' || typeof requestBodyEncodingPair === 'undefined') { |
|
@@ -440,16 +440,16 @@ export const handlePatchItem: Middleware = ({ |
|
|
} |
|
|
} |
|
|
// TODO better error reporting, localizable messages |
|
|
// TODO better error reporting, localizable messages |
|
|
// TODO handle error handlers' errors |
|
|
// TODO handle error handlers' errors |
|
|
const serialized = errorSerializerPair.serialize( |
|
|
|
|
|
|
|
|
const serialized = errorResponseBodyMediaType.serialize( |
|
|
err.issues.map((i) => ( |
|
|
err.issues.map((i) => ( |
|
|
`${i.path?.map((p) => p.key)?.join('.') ?? i.reason}: ${i.message}` |
|
|
`${i.path?.map((p) => p.key)?.join('.') ?? i.reason}: ${i.message}` |
|
|
)), |
|
|
)), |
|
|
); |
|
|
); |
|
|
const encoded = errorEncoding.encode(serialized); |
|
|
|
|
|
|
|
|
const encoded = errorResponseBodyEncoding.encode(serialized); |
|
|
res.writeHead(constants.HTTP_STATUS_BAD_REQUEST, { |
|
|
res.writeHead(constants.HTTP_STATUS_BAD_REQUEST, { |
|
|
...headers, |
|
|
...headers, |
|
|
'Content-Type': errorMediaType, |
|
|
|
|
|
'Content-Encoding': errorEncodingKey, |
|
|
|
|
|
|
|
|
'Content-Type': errorResponseBodyMediaType.name, |
|
|
|
|
|
'Content-Encoding': errorResponseBodyEncoding.name, |
|
|
}) |
|
|
}) |
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.invalidResourcePatch(resource); |
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.invalidResourcePatch(resource); |
|
|
res.end(encoded); |
|
|
res.end(encoded); |
|
@@ -475,7 +475,7 @@ export const handlePatchItem: Middleware = ({ |
|
|
|
|
|
|
|
|
let serialized; |
|
|
let serialized; |
|
|
try { |
|
|
try { |
|
|
serialized = responseBodySerializerPair.serialize(newObject); |
|
|
|
|
|
|
|
|
serialized = responseBodyMediaType.serialize(newObject); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
@@ -489,7 +489,7 @@ export const handlePatchItem: Middleware = ({ |
|
|
|
|
|
|
|
|
let encoded; |
|
|
let encoded; |
|
|
try { |
|
|
try { |
|
|
encoded = encoding.encode(serialized); |
|
|
|
|
|
|
|
|
encoded = responseBodyEncoding.encode(serialized); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
@@ -502,9 +502,9 @@ export const handlePatchItem: Middleware = ({ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
res.writeHead(constants.HTTP_STATUS_OK, { |
|
|
res.writeHead(constants.HTTP_STATUS_OK, { |
|
|
'Content-Type': responseBodyMediaType, |
|
|
|
|
|
|
|
|
'Content-Type': responseBodyMediaType.name, |
|
|
'Content-Language': responseBodyLanguage.name, |
|
|
'Content-Language': responseBodyLanguage.name, |
|
|
'Content-Encoding': encodingKey, |
|
|
|
|
|
|
|
|
'Content-Encoding': responseBodyEncoding.name, |
|
|
}); |
|
|
}); |
|
|
res.statusMessage = responseBodyLanguage.statusMessages.resourcePatched(resource); |
|
|
res.statusMessage = responseBodyLanguage.statusMessages.resourcePatched(resource); |
|
|
res.end(encoded); |
|
|
res.end(encoded); |
|
@@ -519,12 +519,12 @@ export const handleCreateItem: Middleware = ({ |
|
|
appState, |
|
|
appState, |
|
|
serverParams, |
|
|
serverParams, |
|
|
backendState, |
|
|
backendState, |
|
|
responseBodyMediaType: [responseBodyMediaType, responseBodySerializerPair], |
|
|
|
|
|
|
|
|
responseBodyMediaType, |
|
|
responseBodyLanguage, |
|
|
responseBodyLanguage, |
|
|
responseBodyEncoding: [encodingKey, encoding], |
|
|
|
|
|
|
|
|
responseBodyEncoding, |
|
|
errorResponseBodyLanguage, |
|
|
errorResponseBodyLanguage, |
|
|
errorResponseBodyMediaType: [errorMediaType, errorSerializerPair], |
|
|
|
|
|
errorResponseBodyEncoding: [errorEncodingKey, errorEncoding], |
|
|
|
|
|
|
|
|
errorResponseBodyMediaType, |
|
|
|
|
|
errorResponseBodyEncoding, |
|
|
resource, |
|
|
resource, |
|
|
}) => async (req: IncomingMessage, res: ServerResponse) => { |
|
|
}) => async (req: IncomingMessage, res: ServerResponse) => { |
|
|
const { deserializerPair: requestBodyDeserializerPair, encodingPair: requestBodyEncodingPair } = getDeserializerObjects(appState, req); |
|
|
const { deserializerPair: requestBodyDeserializerPair, encodingPair: requestBodyEncodingPair } = getDeserializerObjects(appState, req); |
|
@@ -562,16 +562,16 @@ export const handleCreateItem: Middleware = ({ |
|
|
} |
|
|
} |
|
|
// TODO better error reporting, localizable messages |
|
|
// TODO better error reporting, localizable messages |
|
|
// TODO handle error handlers' errors |
|
|
// TODO handle error handlers' errors |
|
|
const serialized = errorSerializerPair.serialize( |
|
|
|
|
|
|
|
|
const serialized = errorResponseBodyMediaType.serialize( |
|
|
err.issues.map((i) => ( |
|
|
err.issues.map((i) => ( |
|
|
`${i.path?.map((p) => p.key)?.join('.') ?? i.reason}: ${i.message}` |
|
|
`${i.path?.map((p) => p.key)?.join('.') ?? i.reason}: ${i.message}` |
|
|
)), |
|
|
)), |
|
|
); |
|
|
); |
|
|
const encoded = errorEncoding.encode(serialized); |
|
|
|
|
|
|
|
|
const encoded = errorResponseBodyEncoding.encode(serialized); |
|
|
res.writeHead(constants.HTTP_STATUS_BAD_REQUEST, { |
|
|
res.writeHead(constants.HTTP_STATUS_BAD_REQUEST, { |
|
|
...headers, |
|
|
...headers, |
|
|
'Content-Type': errorMediaType, |
|
|
|
|
|
'Content-Encoding': errorEncodingKey, |
|
|
|
|
|
|
|
|
'Content-Type': errorResponseBodyMediaType.name, |
|
|
|
|
|
'Content-Encoding': errorResponseBodyEncoding.name, |
|
|
}) |
|
|
}) |
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.invalidResource(resource); |
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.invalidResource(resource); |
|
|
res.end(encoded); |
|
|
res.end(encoded); |
|
@@ -628,7 +628,7 @@ export const handleCreateItem: Middleware = ({ |
|
|
|
|
|
|
|
|
let serialized; |
|
|
let serialized; |
|
|
try { |
|
|
try { |
|
|
serialized = responseBodySerializerPair.serialize(newObject); |
|
|
|
|
|
|
|
|
serialized = responseBodyMediaType.serialize(newObject); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
@@ -642,7 +642,7 @@ export const handleCreateItem: Middleware = ({ |
|
|
|
|
|
|
|
|
let encoded; |
|
|
let encoded; |
|
|
try { |
|
|
try { |
|
|
encoded = encoding.encode(serialized); |
|
|
|
|
|
|
|
|
encoded = responseBodyEncoding.encode(serialized); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
@@ -655,9 +655,9 @@ export const handleCreateItem: Middleware = ({ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const headers: Record<string, string> = { |
|
|
const headers: Record<string, string> = { |
|
|
'Content-Type': responseBodyMediaType, |
|
|
|
|
|
|
|
|
'Content-Type': responseBodyMediaType.name, |
|
|
'Content-Language': responseBodyLanguage.name, |
|
|
'Content-Language': responseBodyLanguage.name, |
|
|
'Content-Encoding': encodingKey, |
|
|
|
|
|
|
|
|
'Content-Encoding': responseBodyEncoding.name, |
|
|
'Location': `${serverParams.baseUrl}/${resource.state.routeName}/${newId}` |
|
|
'Location': `${serverParams.baseUrl}/${resource.state.routeName}/${newId}` |
|
|
}; |
|
|
}; |
|
|
if (typeof totalItemCount !== 'undefined') { |
|
|
if (typeof totalItemCount !== 'undefined') { |
|
@@ -674,12 +674,12 @@ export const handleCreateItem: Middleware = ({ |
|
|
export const handleEmplaceItem: Middleware = ({ |
|
|
export const handleEmplaceItem: Middleware = ({ |
|
|
appState, |
|
|
appState, |
|
|
serverParams, |
|
|
serverParams, |
|
|
responseBodyMediaType: [responseBodyMediaType, responseBodySerializerPair], |
|
|
|
|
|
|
|
|
responseBodyMediaType, |
|
|
responseBodyLanguage, |
|
|
responseBodyLanguage, |
|
|
responseBodyEncoding: [encodingKey, encoding], |
|
|
|
|
|
|
|
|
responseBodyEncoding, |
|
|
errorResponseBodyLanguage, |
|
|
errorResponseBodyLanguage, |
|
|
errorResponseBodyMediaType: [errorMediaType, errorSerializerPair], |
|
|
|
|
|
errorResponseBodyEncoding: [errorEncodingKey, errorEncoding], |
|
|
|
|
|
|
|
|
errorResponseBodyMediaType, |
|
|
|
|
|
errorResponseBodyEncoding, |
|
|
resource, |
|
|
resource, |
|
|
resourceId, |
|
|
resourceId, |
|
|
backendState, |
|
|
backendState, |
|
@@ -731,16 +731,16 @@ export const handleEmplaceItem: Middleware = ({ |
|
|
} |
|
|
} |
|
|
// TODO better error reporting, localizable messages |
|
|
// TODO better error reporting, localizable messages |
|
|
// TODO handle error handlers' errors |
|
|
// TODO handle error handlers' errors |
|
|
const serialized = errorSerializerPair.serialize( |
|
|
|
|
|
|
|
|
const serialized = errorResponseBodyMediaType.serialize( |
|
|
err.issues.map((i) => ( |
|
|
err.issues.map((i) => ( |
|
|
`${i.path?.map((p) => p.key)?.join('.') ?? i.reason}: ${i.message}` |
|
|
`${i.path?.map((p) => p.key)?.join('.') ?? i.reason}: ${i.message}` |
|
|
)), |
|
|
)), |
|
|
); |
|
|
); |
|
|
const encoded = errorEncoding.encode(serialized); |
|
|
|
|
|
|
|
|
const encoded = errorResponseBodyEncoding.encode(serialized); |
|
|
res.writeHead(constants.HTTP_STATUS_BAD_REQUEST, { |
|
|
res.writeHead(constants.HTTP_STATUS_BAD_REQUEST, { |
|
|
...headers, |
|
|
...headers, |
|
|
'Content-Type': errorMediaType, |
|
|
|
|
|
'Content-Encoding': errorEncodingKey, |
|
|
|
|
|
|
|
|
'Content-Type': errorResponseBodyMediaType.name, |
|
|
|
|
|
'Content-Encoding': errorResponseBodyEncoding.name, |
|
|
}) |
|
|
}) |
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.invalidResource(resource); |
|
|
res.statusMessage = errorResponseBodyLanguage.statusMessages.invalidResource(resource); |
|
|
res.end(encoded); |
|
|
res.end(encoded); |
|
@@ -781,7 +781,7 @@ export const handleEmplaceItem: Middleware = ({ |
|
|
|
|
|
|
|
|
let serialized; |
|
|
let serialized; |
|
|
try { |
|
|
try { |
|
|
serialized = responseBodySerializerPair.serialize(newObject); |
|
|
|
|
|
|
|
|
serialized = responseBodyMediaType.serialize(newObject); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
@@ -795,7 +795,7 @@ export const handleEmplaceItem: Middleware = ({ |
|
|
|
|
|
|
|
|
let encoded; |
|
|
let encoded; |
|
|
try { |
|
|
try { |
|
|
encoded = encoding.encode(serialized); |
|
|
|
|
|
|
|
|
encoded = responseBodyEncoding.encode(serialized); |
|
|
} catch { |
|
|
} catch { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
res.writeHead(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, { |
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
|
'Content-Language': errorResponseBodyLanguage.name, |
|
@@ -808,9 +808,9 @@ export const handleEmplaceItem: Middleware = ({ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const headers: Record<string, string> = { |
|
|
const headers: Record<string, string> = { |
|
|
'Content-Type': responseBodyMediaType, |
|
|
|
|
|
|
|
|
'Content-Type': responseBodyMediaType.name, |
|
|
'Content-Language': responseBodyLanguage.name, |
|
|
'Content-Language': responseBodyLanguage.name, |
|
|
'Content-Encoding': encodingKey, |
|
|
|
|
|
|
|
|
'Content-Encoding': responseBodyEncoding.name, |
|
|
}; |
|
|
}; |
|
|
let totalItemCount: number | undefined; |
|
|
let totalItemCount: number | undefined; |
|
|
if (backendState.showTotalItemCountOnCreateItem && typeof resource.dataSource.getTotalCount === 'function') { |
|
|
if (backendState.showTotalItemCountOnCreateItem && typeof resource.dataSource.getTotalCount === 'function') { |
|
|