Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/snyk.project.settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions fileManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const express = require('express');
const fs = require('fs');
const path = require('path');
const app = express();

app.get('/file', (req, res) => {
let fileName = req.query.filename;
fs.readFile(path.join(__dirname, fileName), 'utf8', (err, data) => {
if (err) {
res.status(404).send('Not found');
} else {
res.send(data);
}
});
});

app.listen(3000, () => console.log('Listening on port 3000'));
35 changes: 32 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
const express = require('express');
const config = require('./config/VTSconfig.js');
const vehicleDb = require('./dbInterface/vehicleDB_test.js');
//const vehicleDb = require('./dbInterface/vehicleDb.js');
//const vehicleDb = require('./dbInterface/vehicleDB_test.js');
const vehicleDb = require('./dbInterface/vehicleDb.js');

const app = express();


app.listen(config.PORT, () =>
console.log(`Vehicle Telemetry Service is listening on port ${config.PORT}!`),
);
);

app.get(config.urlPrefix+`vehicles/list`, (req, res) =>{
let vehicleList = vehicleDb.getVehicleList();
return res.send(vehicleList);
})

app.get(config.urlPrefix+`vehicles/:vehicleId`, (req,res) => {
let vehicleDetail = vehicleDb.getVehicleDetails(req.params.vehicleId);
return res.send(vehicleDetail);
})

app.put(config.urlPrefix+'vehicles/:vehicleId', (req, res) => {
reqAction = req.params.reqAction;
returnValue = "";
switch(toUpper(reqAction)) {
case "RESERVE":
returnValue = vehicelDb.reserveVehicle(req.params.vehicleId);
break;
case "BOOK":
returnValue = vehicelDb.reserveVehicle(req.params.vehicleId);
break;
default:
returnValue = "ERROR: Unknown verb";
break;
}

return returnValue;

})
40 changes: 40 additions & 0 deletions kubernetes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: CarSharingDemo
labels:
app: web
spec:
selector:
matchLabels:
octopusexport: OctopusExport
replicas: 1
strategy:
type: RollingUpdate
template:
metadata:
labels:
app: web
octopusexport: OctopusExport
spec:
containers:
- name: nodeserver
image: 'node:10-alpine'
securityContext:
runAsNonRoot: true
ports:
- name: Express
containerPort: 8080
protocol: TCP
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: app
operator: In
values:
- web
topologyKey: kubernetes.io/hostname
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"homepage": "https://github.com/CU-0xff/DemoCarSharing#readme",
"dependencies": {
"express": "^4.17.1",
"mysql": "^2.18.1"
"mysql": "^2.18.1",
"lodash" : "2.4.2"
}
}
24 changes: 24 additions & 0 deletions python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from flask import Flask, jsonify
import requests
import os

app = Flask(__name__)

@app.route('/get_file_content', methods=['GET'])
def get_file_content():
# Get JSON response from the web service
response = requests.get('http://jsonwebservice.com/path') # Replace with your actual URL
data = response.json()

# Extract file path
file_path = data.get('file_path')

if file_path and os.path.isfile(file_path):
with open(file_path, 'r') as file:
file_content = file.read()
return jsonify({'file_content': file_content}), 200
else:
return jsonify({'error': 'Invalid file path'}), 400

if __name__ == '__main__':
app.run(port=5000)