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

Missing headers in response #4

Open
jrnail23 opened this issue Dec 2, 2015 · 0 comments
Open

Missing headers in response #4

jrnail23 opened this issue Dec 2, 2015 · 0 comments

Comments

@jrnail23
Copy link

jrnail23 commented Dec 2, 2015

When using express-cors with the ETag header included in cors options.headers, the ETag header is still missing.

Here's my relevant setup code:

import express from 'express'
import cors from 'express-cors'

const app = express()

const corsOptions = {
  allowedOrigins: ['localhost:*'],
  headers: ['Content-Type', 'X-Requested-With', 'Location', 'ETag']
}

app.use(cors(corsOptions))

My api route:

  membersRouter.route('/')
    .get((req, res) => {
      Promise.using(
        getDbConnection(),
        query => query('SELECT key, first_name, last_name, email_address FROM member')
      ).get('rows')
        .map(mapRowToMember)
        .then(rows => res.json(rows))
    })

Plus my client request:

import request from 'request'

request({
    method: 'GET',
    json: true,
    uri: 'http://localhost:9006/members'
  })
    .on('response', res => {
      console.log(res.statusCode)
      console.log(res.headers)
    })

Here are the raw response headers received from my API, when called from DHC (REST client):

X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 390
ETag: W/"186-WNgZ5jX8cc8PCX+6dY5Ihw"
Date: Wed, 25 Nov 2015 23:26:12 GMT
Connection: keep-alive

but when making that same request using request in my SPA app, I only get this header:

content-type: "application/json; charset=utf-8"

As seen in request/request#1890 (comment), this can be resolved by the following:

Access-Control-Expose-Headers with value = a comma separated list of the headers I wanted to receive in the response.

Can we add the appropriate means to use Access-Control-Expose-Headers to express-cors

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant