diff --git a/server/src/app.js b/server/src/app.js index 6f08f06..a2f9d30 100644 --- a/server/src/app.js +++ b/server/src/app.js @@ -9,9 +9,6 @@ import morgan from 'morgan'; import route from './route'; import logger, { stream } from './logger'; - -const ENV = process.env.NODE_ENV; - const sendError = (err, req, res) => { logger.error(err.stack); const code = err.status || 500; @@ -52,13 +49,18 @@ export default () => { const app = express(); app.use(expressRequestId()); - if (ENV === 'development') app.use(cors()); + app.use(cors()); app.use(compression()); app.use(bodyParser.json()); app.use(bodyParser.urlencoded()); app.use(sseMiddleware); app.use(morgan('tiny', { stream })); + // HealthCheck Endpoint + app.get('/', async (_req, res) => { + res.send('OK'); + }); + app.use('/api', route); app.use('/', express.static('build')); app.use('*', (req, res) => { diff --git a/server/src/db/query.js b/server/src/db/query.js index cd1d20e..0aeb49d 100644 --- a/server/src/db/query.js +++ b/server/src/db/query.js @@ -64,11 +64,13 @@ export const listQuery = ({ return params; }; -export const listQueryWithCount = (model, ...args) => { +export const listQueryWithCount = async (model, ...args) => { const params = listQuery(...args); const { offset } = params; - return model.findAndCountAll(params).then(({ count, rows }) => ({ + const count = await model.max('id'); + const rows = await model.findAll(params); + return { data: rows, pagination: { count: rows.length, offset, total: count }, - })); + }; };