Browse Source

Maybe with preflight requests?

Brendan Abolivier 8 years ago
parent
commit
d53cec98a6
Signed by: Brendan Abolivier <contact@brendanabolivier.com> GPG key ID: 8EF1500759F70623
1 changed files with 6 additions and 3 deletions
  1. 6
    3
      server.js

+ 6
- 3
server.js View File

31
 app.use(bodyParser.urlencoded({ extended: true }));
31
 app.use(bodyParser.urlencoded({ extended: true }));
32
 app.use(bodyParser.json());
32
 app.use(bodyParser.json());
33
 // Allow cross-origin requests.
33
 // Allow cross-origin requests.
34
-app.use(cors({
34
+var corsOptions = {
35
   origin: settings.formUrl,
35
   origin: settings.formUrl,
36
   optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204
36
   optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204
37
-}));
37
+};
38
+app.use(cors(corsOptions));
38
 
39
 
39
-app.all('/*', function(req, res, next) {
40
+app.options('*', cors(corsOptions));
41
+
42
+app.all('*', function(req, res, next) {
40
     res.header('Access-Control-Allow-Headers', 'Content-Type')
43
     res.header('Access-Control-Allow-Headers', 'Content-Type')
41
     next();
44
     next();
42
 });
45
 });