import path from 'path'; import favicon from 'serve-favicon'; import compress from 'compression'; import helmet from 'helmet'; import cors from 'cors'; import feathers from '@feathersjs/feathers'; import configuration from '@feathersjs/configuration'; import express from '@feathersjs/express'; <% if (hasProvider('socketio')) { %>import socketio from '@feathersjs/socketio';<% } %> <% if (hasProvider('primus')) { %>import primus from '@feathersjs/primus';<% } %> import { Application } from './declarations'; import logger from './logger'; import middleware from './middleware'; import services from './services'; import appHooks from './app.hooks'; import channels from './channels'; import { HookContext as FeathersHookContext } from '@feathersjs/feathers'; // Don't remove this comment. It's needed to format import lines nicely. const app: Application = express(feathers()); export type HookContext = { app: Application } & FeathersHookContext; // Load app configuration app.configure(configuration()); // Enable security, CORS, compression, favicon and body parsing app.use(helmet({ contentSecurityPolicy: false })); app.use(cors()); app.use(compress()); app.use(express.json()); app.use(express.urlencoded({ extended: true })); app.use(favicon(path.join(app.get('public'), 'favicon.ico'))); // Host the public folder app.use('/', express.static(app.get('public'))); // Set up Plugins and providers <% if (hasProvider('rest')) { %>app.configure(express.rest());<% } %> <% if (hasProvider('socketio')) { %>app.configure(socketio());<% } %> <% if(hasProvider('primus')) { %>app.configure(primus({ transformer: 'websockets' }));<% } %> // Configure other middleware (see `middleware/index.ts`) app.configure(middleware); // Set up our services (see `services/index.ts`) app.configure(services); // Set up event channels (see channels.ts) app.configure(channels); // Configure a middleware for 404s and the error handler app.use(express.notFound()); app.use(express.errorHandler({ logger } as any)); app.hooks(appHooks); export default app;