-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
48 lines (37 loc) · 1.08 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
const express = require('express');
var os = require('os');
var fs = require('fs');
const request = require('request');
const dotenv = require('dotenv');
// Constants
const PORT = 8888;
const HOST = '0.0.0.0';
// App
const app = express();
dotenv.config();
var content = 'Namaste - Bharat ' + process.env.USER + ' ' + os.hostname();
app.get('/', (req, res) => {
res.send(content);
});
app.get('/savefile', (req,res) => {
fs.writeFile('mynewfile.txt', content, function (err) {
if (err) throw err;
console.log('Replaced!');
});
});
app.get('/weather', (req, res) => {
console.log('The weather Service is at:' + process.env.WeatherService);
// fetch('http://localhost:32000/weatherforecast')
// .then(res => res.json())
// .then(json => {
// console.log(json);
// content = json;
// });
request('http://mintnodeapp-service.default.svc.cluster.local:32000/weatherforecast',(err,resp,body) => {
content = JSON.stringify(body);
});
res.send(content);
});
app.listen(PORT, HOST);
console.log(`Running on http://${HOST}:${PORT}`);