mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 17:12:43 +00:00
committed by
Rainer Killinger
parent
12b71ba1f1
commit
e70e50a1ea
@@ -14,8 +14,8 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
import {
|
import {
|
||||||
SCInternalServerErrorResponse,
|
|
||||||
SCNotFoundErrorResponse,
|
SCNotFoundErrorResponse,
|
||||||
|
SCRequestBodyTooLargeErrorResponse,
|
||||||
SCSyntaxErrorResponse,
|
SCSyntaxErrorResponse,
|
||||||
SCUnsupportedMediaTypeErrorResponse,
|
SCUnsupportedMediaTypeErrorResponse,
|
||||||
} from '@openstapps/core';
|
} from '@openstapps/core';
|
||||||
@@ -47,11 +47,14 @@ async function configureApp() {
|
|||||||
|
|
||||||
// only accept json as content type for all requests
|
// only accept json as content type for all requests
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
// Get the content type
|
// get the content type
|
||||||
let contentType = '';
|
let contentType = '';
|
||||||
|
// the content type can be string, string[] or undefined
|
||||||
if (typeof req.headers['Content-Type'] === 'string') {
|
if (typeof req.headers['Content-Type'] === 'string') {
|
||||||
|
// weird type definitions require an explicit cast
|
||||||
contentType = req.headers['Content-Type'] as string;
|
contentType = req.headers['Content-Type'] as string;
|
||||||
} else if (typeof req.headers['content-type'] === 'string') {
|
} else if (typeof req.headers['content-type'] === 'string') {
|
||||||
|
// weird type definitions require no cast here though...
|
||||||
contentType = req.headers['content-type'];
|
contentType = req.headers['content-type'];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +73,7 @@ async function configureApp() {
|
|||||||
if (bodySize > 512 * 1024) {
|
if (bodySize > 512 * 1024) {
|
||||||
req.off('data', chunkGatherer);
|
req.off('data', chunkGatherer);
|
||||||
req.off('end', endCallback);
|
req.off('end', endCallback);
|
||||||
const err = new SCInternalServerErrorResponse(new Error('Request body is too large!'), isTestEnvironment);
|
const err = new SCRequestBodyTooLargeErrorResponse(isTestEnvironment);
|
||||||
res.status(err.statusCode);
|
res.status(err.statusCode);
|
||||||
res.json(err);
|
res.json(err);
|
||||||
return;
|
return;
|
||||||
|
|||||||
12
src/cli.ts
12
src/cli.ts
@@ -86,12 +86,8 @@ function onError(error: Error | any) {
|
|||||||
*/
|
*/
|
||||||
function onListening() {
|
function onListening() {
|
||||||
const addr = server.address();
|
const addr = server.address();
|
||||||
if (addr === null) {
|
const bind = typeof addr === 'string'
|
||||||
logger.warn('Listening on null');
|
? 'pipe ' + addr
|
||||||
} else {
|
: 'port ' + addr.port;
|
||||||
const bind = typeof addr === 'string'
|
logger.ok('Listening on ' + bind);
|
||||||
? 'pipe ' + addr
|
|
||||||
: 'port ' + addr.port;
|
|
||||||
logger.ok('Listening on ' + bind);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user