0

EDIT : I changed the port used, before 8081, but still have a problem with the error 405 with my index.js. Organization looks like

├── ...
├── site
│   ├── server
│   │   ├── index.js
│   │   ├── ...
│   ├── wwwroot
│   │   ├── index.html
│   │   ├── .htaccess
│   │   ├── manifest.json
│   │   ├── web.config
│   │   ├── ...

I used for the first time MS Azure. I did a project on React.js with a MySQL db. I now sent my build on a Web App on MS Azure, which worked well.

But in that app, I use a fetch request, which I don't know how to config for MS Azure with the authorizations. I tried to fetch on XX.XX.XXXX:443/dot.

I have next an error 405. I tried to put an .htaccess file: Header set Access-Control-Allow-Methods: POST, GET, OPTIONS, HEAD but it changed nothing, the post method is still unavailable.

I really hope someone will find a solution, thanks.

Here is the index.js important code:

const version="1.0.0"

var app=require('express')();
var http=require('http').Server(app);
var mysql=require('mysql');
var bodyParser=require('body-parser');
var jwt = require('jsonwebtoken');
var cookieParser = require('cookie-parser');
var fs=require("fs");

app.use(bodyParser.json({limit:'50mb'}));
app.use(bodyParser.urlencoded({limit:'50mb',extended:true}));
app.use(cookieParser());

const CREATE_TABLE_USER = fs.readFileSync("src/sql_script/create_table_user.sql").toString();
const ...

var con=mysql.createConnection({
    host:"host",
    user:"user",
    password:"password",
    database:"database",
});

con.connect(function(err){if(err){console.log(err);}});

con.query(CREATE_TABLE_USER,function(err,result){if(err){console.log(err);}})
con.query...

app.use(function(req,res,next){
    res.header('Access-Control-Allow-Methods: GET,POST,PATCH,PUT,DELETE,OPTIONS');
    res.header('Access-Control-Allow-Headers: Origin,X-Requested-With,Content-Type,Accept,X-Auth-Token');
    checkValidToken(req,res,next);
});

app.post('/dot',function(req,res){
    if(req.body.action === "login"){login(req, res);}
    ...
});

http.listen(443,function(){console.log('app listening on port 443!');})

Here is the app fetch function:

return fetch("XX:443/dot",{
    method:"POST",
    credentials:'same-origin',
    body:JSON.stringify(info),
    headers:{'Content-Type':'application/json'}
});
Nemzytch
  • 171
  • 1
  • 1
  • 7
  • 2
    How did you deploy? If it's a web app, you cannot listen on 8081 (only 80 and 443 are open); you'd have to deploy a different way. – David Makogon Apr 01 '19 at 00:56
  • I built my react app and did put on the created web app on ms azure pannel, with an already made hosting file, and it worked perfectly. So, according to you, it would work if I only use 80 or 443 instead of 8081? I try it right now, and come back when it's done (plus I already made before access rules for 80 and 443 :) ) – Nemzytch Apr 01 '19 at 13:14

0 Answers0