Skip to content

Commit

Permalink
Convert to ES Modules (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielrozenberg authored Nov 16, 2023
1 parent ef7e9f0 commit f82ae70
Show file tree
Hide file tree
Showing 34 changed files with 1,666 additions and 316 deletions.
26 changes: 26 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['sort-destructure-keys'],
env: {
es6: true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:import/recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
rules: {
'sort-destructure-keys/sort-destructure-keys': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{ varsIgnorePattern: 'unused' },
],
},
};
16 changes: 0 additions & 16 deletions .eslintrc.js

This file was deleted.

4 changes: 4 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "es5"
}
21 changes: 11 additions & 10 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@
* limitations under the License.
*/

const express = require('express');
const { StatusCodes } = require('http-status-codes');
import express from 'express';
import { StatusCodes } from 'http-status-codes';

const errorTracker = require('./routes/error-tracker');
const parseErrorHandling = require('./utils/requests/parse-error-handling');
import errorTracker from './routes/error-tracker.js';
import parseErrorHandling from './utils/requests/parse-error-handling.js';

const app = express();
const BODY_LIMIT = 10 * 1024; /* 10kb */
const jsonParser = express.json({
limit: BODY_LIMIT,
type: () => true,
});

const app = express();
function rawJsonBodyParserMiddleware(req, res, next) {
if (!req.rawBody) {
// Defer to bodyParser when running as a server.
jsonParser = express.json({
limit: BODY_LIMIT,
type: () => true,
});
jsonParser(req, res, next);
} else if (req.rawBody.length > BODY_LIMIT) {
// When Cloud Functions hijacks the request, validate and parse it manually.
Expand All @@ -55,4 +56,4 @@ app.post('*', (req, res) => {
return errorTracker(req, res);
});

module.exports = app;
export default app;
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
* limitations under the License.
*/

const app = require('./app');
module.exports = { app };
import app from './app.js';

export { app };
Loading

0 comments on commit f82ae70

Please sign in to comment.