-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
41 lines (32 loc) · 1.01 KB
/
app.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
const express = require("express");
const bodyParser = require("body-parser");
const ejs = require("ejs");
const app = express();
app.use(express.static('public'));
app.use(bodyParser.urlencoded({extended: true}));
app.set('view engine', 'ejs');
// Home route
app.get("/", function(req, res){
res.render('index');
});
// Display solution
app.post("/solution", function(req, res){
const boardConfig = req.body.queenArray;
var spawn = require("child_process").spawn;
var process = spawn('python3', ["./8queens.py", boardConfig]);
process.stdout.on('data', function(data){
const received = data.toString()
const l = received.length;
const steps = received.substring(0, l-2);
const ofv = received.substring(l-2,l-1);
res.render('solution', {solnSteps: steps, objFuncVal: ofv});
});
});
// Any other route = 404
app.get('*', function(req, res){
res.render('404-error');
});
// Running the server
app.listen(process.env.PORT || 3000, function(){
console.log("Server started on port 3000");
});