/** * Backend Express HTTP server. * @module app/index */ import express from "express"; import http from "http"; import bodyParser from "body-parser"; import compression from "compression"; import cors from "cors"; import morgan from "morgan"; // import multer from 'multer' import services from "app/services"; /** * Create the API server. * @param {Knex} knex an existing Knex instance (optional, used in test scripts) * @return {Object} an Express app and HTTP server */ export default async function createServer(knex) { const app = new express(); const server = http.createServer(app); app.disable("x-powered-by"); app.use( morgan("dev", { skip: (request) => request.method === "OPTIONS", }) ); app.use(bodyParser.json({ limit: "100mb" })); app.use(bodyParser.urlencoded({ extended: false, limit: "100mb" })); app.use(express.query()); app.use(compression()); app.set("trust proxy", true); if (process.env.NODE_ENV === "development") { const corsMiddleware = cors({ origin: ["http://localhost:3000", "http://0.0.0.0:3000"], }); app.use(corsMiddleware); app.options("*", corsMiddleware); } await services.configure(app, knex); return { app, server }; }