Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var express = require('express');
- var app = express();
- var fs = require('fs');
- var http = require('http');
- var https = require('https');
- var path = require('path');
- var axios = require('axios');
- //var cors = require('cors');
- //app.use(cors());
- app.use(function(req, res, next) {
- if (req.secure) {
- next();
- } else {
- res.redirect('https://' + req.headers.host + req.url);
- }
- });
- const httpsAgent = new https.Agent({
- rejectUnauthorized: false,
- cert: fs.readFileSync('sec/kbadower.net.crt')
- })
- app.use(express.static(__dirname + '/public'));
- app.get('/', function(req, res) {
- res.sendFile(path.join(__dirname + 'public/index.html'));
- });
- app.get('/rest', function(req, res) {
- axios.get('https://kbadower.net:3000/basic' , { httpsAgent, auth: { username: 'qwer', password: '1234'}}) // lab
- .then(function(response){
- console.log(response.data)
- res.send(response.data)
- })
- .catch(function(e) { console.log(e); res.write(JSON.stringify(e)); })
- });
- app.post('/rest', function(req, res) {
- axios.post('https://kbadower.net:3000/basic', { // lab
- a : "44",
- }, { httpsAgent })
- .then(function (response) {
- res.send(response.data)
- })
- .catch(function(e) { console.log(e); res.write(JSON.stringify(e)); })
- });
- var key = fs.readFileSync('sec/kbadower.org.key');
- var cert = fs.readFileSync('sec/kbadower.org.crt');
- var options = {
- key: key,
- cert: cert
- };
- https.createServer(options, app).listen(443)
- http.createServer(app).listen(80);
- console.log(`Router.js listening on ports 443(https) and 80(http)!`)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement