- Timestamp:
- 2022-07-29T22:20:27+12:00 (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/bib-stinky/trunk/nodejs-server/express-web-server.js
r36333 r36350 1 1 // Setup Express 2 const path = require('path'); 3 const { spawn } = require('child_process'); 2 const path = require('path'); 4 3 5 4 const express = require("express"); 6 5 const cors = require("cors"); 7 8 6 9 7 const app = express(); … … 12 10 const public_dir = path.join(__dirname, 'public') 13 11 14 15 12 app.use(cors()); 16 13 app.use('/', express.static(public_dir)) 17 14 18 // // To help with POST and PUT requests to the server19 // app.use(express.json());20 // app.use(express.urlencoded({ extended: true }));15 // // To help with POST and PUT requests to the server 16 // app.use(express.json()); 17 // app.use(express.urlencoded({ extended: true })); 21 18 22 19 … … 25 22 }); 26 23 27 28 app.get("/api/get-doi", (req, res) => { 29 var doi = req.query.doi; 30 31 var dataToSend; 32 33 // Spawn new child process to call the python script 34 const python = spawn('python3', ['doi-stinky/oacore-get-doi.py', doi, "oacore-output.json"]); 35 36 // Collect data from script 37 python.stdout.on('data', function (data) { 38 console.log('Pipe data from python script ...'); 39 dataToSend = data.toString(); 40 }); 41 42 // In close event we are sure that stream from child process is closed 43 python.on('close', (code) => { 44 console.log(`child process close all stdio with code ${code}`); 45 46 //res.send(dataToSend) 47 res.sendFile("oacore-output.json", { root: __dirname }); 48 }); 49 }); 24 require("./api.routes.js")(app); 50 25 51 26
Note:
See TracChangeset
for help on using the changeset viewer.