I'm getting net::ERR_CONNECTION_REFUSED error when i open related page with javascript file. I'm using node.js as a server and , i'm writing post requests in a javascript file for my static pages. service_provider.js is my javascript file for i use writing javascript functions for my static pages(html). node.js is my node.js server file.
service_provider.js
function getJourneyAnalize(
_fonkSuccess,
_fonkBefore,
_fonkError,
_deviceId,
_driverId,
_dateStart,
_dateEnd,
_timeStart,
_timeEnd,
_map,
_kmStart,
_kmEnd
) {
var _fromBody = {
device_id: _deviceId,
driver_id: _driverId,
date_start: _dateStart,
date_end: _dateEnd,
time_start: _timeStart,
time_end: _timeEnd,
map: _map,
km_start: _kmStart,
km_end: _kmEnd
};
$.ajax({
type: 'POST',
url: apiUrl + '/ReportFms/JourneyAnalize',
data: JSON.stringify(_fromBody),
dataType: 'json',
cache: false,
contentType: 'application/json; charset=utf-8',
beforeSend: function (xhr, settings) {
_fonkBefore();
xhr.setRequestHeader('Authorization', 'Bearer ' + currentUser.access_token);
},
success: _fonkSuccess,
error: _fonkError
});
}
node.js
const express = require('express');
const app = express();
var path = require('path');
app.use(
function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
res.setHeader('Access-Control-Allow-Credentials', true);
next();
}
)
app.use('/node_modules/jquery/dist', express.static(path.join(__dirname, '../node_modules/jquery/dist')))
app.get('/static-pages/journey-analize-report', function (req, res) {
res.sendFile(path.join(__dirname + '/../static-pages/journey-analize-report/index.html'))
})
app.listen(8000, () => {
console.log('server started');
})