-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
44 lines (34 loc) · 976 Bytes
/
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
const express = require('express')
const app = express()
const bodyParser = require('body-parser')
const url = "mongodb+srv://cweston0727:[email protected]/pali?retryWrites=true&w=majority"
const dbName = "Pali";
app.set('view engine', 'ejs')
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
app.use(express.static('public'))
app.get('/', (req, res) => {
res.render('index.ejs')
})
app.get('/api', (req, res) => {
if (req.query.input) {
let str = req.query.input
let re = /[^A-Za-z0-9]/g;
let checkStr = str.toLowerCase().replace(re, '')
const newStr = checkStr.split('').reverse().join('');
let isTrue = null
if (newStr === checkStr) {
isTrue = true
}
else {
isTrue = false
}
const objToJson = {
isPali: isTrue,
originalWord: checkStr,
reverseWord: newStr
}
res.send(objToJson);
}
})
app.listen(8015, console.log('running'));