@@ -6,7 +6,7 @@ const tsKoaApp = ({ transports }: AppGeneratorContext) =>
66 `import serveStatic from 'koa-static'
77import { feathers } from '@feathersjs/feathers'
88import configuration from '@feathersjs/configuration'
9- import { koa, rest, bodyParser, errorHandler, parseAuthentication } from '@feathersjs/koa'
9+ import { koa, rest, bodyParser, errorHandler, parseAuthentication, cors } from '@feathersjs/koa'
1010${ transports . includes ( 'websockets' ) ? "import socketio from '@feathersjs/socketio'" : '' }
1111
1212import type { Application } from './declarations'
@@ -23,12 +23,21 @@ app.configure(configuration(configurationSchema))
2323// Set up Koa middleware
2424app.use(serveStatic(app.get('public')))
2525app.use(errorHandler())
26+ app.use(cors())
2627app.use(parseAuthentication())
2728app.use(bodyParser())
2829
2930// Configure services and transports
3031app.configure(rest())
31- ${ transports . includes ( 'websockets' ) ? 'app.configure(socketio())' : '' }
32+ ${
33+ transports . includes ( 'websockets' )
34+ ? `app.configure(socketio({
35+ cors: {
36+ origin: app.get('origins')
37+ }
38+ }))`
39+ : ''
40+ }
3241app.configure(services)
3342app.configure(channels)
3443
@@ -52,11 +61,10 @@ export { app }
5261
5362const tsExpressApp = ( { transports } : AppGeneratorContext ) =>
5463 `import compress from 'compression'
55- import helmet from 'helmet'
5664
5765import { feathers } from '@feathersjs/feathers'
5866import express, {
59- rest, json, urlencoded,
67+ rest, json, urlencoded, cors,
6068 serveStatic, notFound, errorHandler
6169} from '@feathersjs/express'
6270import configuration from '@feathersjs/configuration'
@@ -72,7 +80,7 @@ const app: Application = express(feathers())
7280
7381// Load app configuration
7482app.configure(configuration(configurationSchema))
75- app.use(helmet ())
83+ app.use(cors ())
7684app.use(compress())
7785app.use(json())
7886app.use(urlencoded({ extended: true }))
@@ -81,7 +89,15 @@ app.use('/', serveStatic(app.get('public')))
8189
8290// Configure services and real-time functionality
8391app.configure(rest())
84- ${ transports . includes ( 'websockets' ) ? 'app.configure(socketio())' : '' }
92+ ${
93+ transports . includes ( 'websockets' )
94+ ? `app.configure(socketio({
95+ cors: {
96+ origin: app.get('origins')
97+ }
98+ }))`
99+ : ''
100+ }
85101app.configure(services)
86102app.configure(channels)
87103
0 commit comments