-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (33 loc) · 989 Bytes
/
index.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
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const sudokuSolver = require('./src/sudokuSolver');
const dataInvestigators = require('./src/dataInvestigators');
const app = express();
const port = 6969;
const corsOptions = {
origin: 'http://localhost:3000',
optionsSuccessStatus: 200
}
app.use(cors(corsOptions));
app.use(bodyParser.json());
app.get('/', (req, res) => {
res.send('Hello World!')
});
app.post('/solve', (req, res) => {
const bodyData = req.body;
let fieldData = bodyData;
if (bodyData.data) {
fieldData = bodyData.data;
}
if (dataInvestigators.validateGameField(fieldData)) {
const filledGame = sudokuSolver.solveGame(fieldData);
res.send(filledGame);
} else {
console.log("fail");
res.status(400).send("Invalid input");
}
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
});