javascript - Node api preflight failed in postman -


when calling api https://mywebsite.com/api/register through browser , returns correct response server { "error": false, "message": "hello world" } if hit same request postman returns html content please enable javascript view page content. below node side code:

var express = require("express");  var app = express();  var bodyparser = require("body-parser");  var router = express.router();  var fs = require('fs'); var https = require('https');  var cors = require('cors');  app.use(cors());  app.use(bodyparser.json({limit: '50mb'}));  app.use(bodyparser.urlencoded({ limit: '50mb', "extended": false }));  var privatekey  = fs.readfilesync('key.pem'); var certificate = fs.readfilesync('cert.pem'); var passphrase = 'testphrase'; var credentials = {key: privatekey, cert: certificate, passphrase:passphrase};  router.get("/", function (req, res) {      res.json({ "error": false, "message": "hello world" });  }); app.use('/api', router); var server = https.createserver(credentials, app).listen(8080); 

the api working through browser not postman. possible errors? please help. thanks!

you missed define api server

const api = require('./{your api path}/api'); // set our api routes app.use('/api', api); 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -