Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
feat: add CORS configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtechsimetka committed May 26, 2020
1 parent b4cfc3d commit 1feab4f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ file and load that either using the `--config` CLI parameter or using environmen
- `RIFM_PORT` (number): port on which the server should listen to
- `RIFM_DB` (string): database connection URI
- `RIFM_PROVIDER` (string): blockchain connection URI
- CORS settings ([see more on expressjs documentation](https://expressjs.com/en/resources/middleware/cors.html)):
- `RIFM_CORS_ORIGIN` (boolean | string | regexp): Configures the Access-Control-Allow-Origin CORS header
- `RIFM_CORS_METHODS` (string) Configures the Access-Control-Allow-Methods CORS header
- Storage related:
- `RIFM_STORAGE_CONTRACT_ADDR` (string): address of deployed storage contract
- `RIFM_STORAGE_STARTING_BLOCK` (number | string): block from which the caching service should process events
Expand Down
5 changes: 5 additions & 0 deletions config/custom-environment-variables.json5
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
port: 'RIFM_PORT',
db: 'RIFM_DB',

cors: {
origin: "RIFM_CORS_ORIGIN",
methods: "RIFM_CORS_METHODS"
},

blockchain: {
provider: "RIFM_PROVIDER",
},
Expand Down
6 changes: 6 additions & 0 deletions config/default.json5
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
port: null,
db: 'sqlite:db.sqlite',

// CORS setting, please consult https://expressjs.com/en/resources/middleware/cors.html for more details
cors: {
origin: '*',
methods: 'GET,HEAD'
},

log: {
level: "info",
filter: null,
Expand Down
7 changes: 5 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import compress from 'compression'
import helmet from 'helmet'
import cors from 'cors'
import cors, { CorsOptionsDelegate } from 'cors'
import config from 'config'

import feathers from '@feathersjs/feathers'
import express from '@feathersjs/express'
Expand Down Expand Up @@ -37,9 +38,11 @@ export function isSupportedServices (value: any): value is SupportedServices {
export function appFactory (): Application {
const app: Application = express(feathers())

const corsOptions: CorsOptionsDelegate = config.get('cors')

// Enable security, CORS, compression and body parsing
app.use(helmet())
app.use(cors())
app.use(cors(corsOptions))
app.use(compress())
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
Expand Down

0 comments on commit 1feab4f

Please sign in to comment.