100 lines
2.3 KiB
JavaScript
Raw Normal View History

2021-07-12 07:15:58 -05:00
const express = require('express')
const axios = require('axios')
var http = require('http');
var https = require('https');
const fs = require('fs');
2021-08-12 04:04:21 -05:00
const sh = require('secrethash');
2021-07-12 07:15:58 -05:00
var key = fs.readFileSync('./projectdivar.com/privkey1.pem');
var cert = fs.readFileSync('./projectdivar.com/cert1.pem');
var options = {
key: key,
cert: cert
};
2021-08-12 04:04:21 -05:00
const app = express()
2021-07-12 07:15:58 -05:00
2021-08-19 12:36:18 -05:00
var server = https.createServer(options, app);
const port = 4505
2021-07-12 07:15:58 -05:00
server.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))
const bodyParser = require('body-parser')
const { json } = require('body-parser')
const moment = require('moment');
const Pool = require('pg').Pool
app.use(bodyParser.json())
app.use(
bodyParser.urlencoded({
extended: true,
})
)
let allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', "*");
res.header('Access-Control-Allow-Headers', "*");
res.header('Access-Control-Allow-Methods', "*");
next();
}
app.use(allowCrossDomain);
var db =
2021-07-12 07:15:58 -05:00
new Pool({
user: 'postgres',
password: '',
host: 'postgres',
2021-08-19 12:36:18 -05:00
database: 'sigcrafting',
2021-07-12 07:15:58 -05:00
port: 5432,
})
2021-08-19 12:36:18 -05:00
app.get('/',async(req,res)=>{
res.status(200).send('BUN is love, BUN is life.')
2021-08-06 05:41:52 -05:00
})
2021-08-19 12:36:18 -05:00
app.get('/getData',(req,res)=>{
db.query('select * from crafting_list order by id asc')
.then((data)=>{
if (data.rows.length>0) {
2021-08-09 05:29:00 -05:00
res.status(200).json(data.rows)
} else {
2021-08-19 12:36:18 -05:00
res.status(204).send("No data")
2021-08-09 05:29:00 -05:00
}
})
2021-08-19 12:36:18 -05:00
.catch((err)=>{
res.status(500).send(err.message)
2021-08-06 07:57:37 -05:00
})
2021-08-19 12:36:18 -05:00
})
2021-08-09 05:29:00 -05:00
2021-08-19 12:36:18 -05:00
app.get('/lastUpdate',(req,res)=>{
db.query("select * from site_data limit 1")
.then((data)=>{
res.status(200).json(data.rows)
2021-08-06 07:57:37 -05:00
})
2021-08-19 12:36:18 -05:00
.catch((err)=>{
res.status(500).send(err.message)
2021-08-06 07:57:37 -05:00
})
2021-08-19 12:36:18 -05:00
})
2021-08-06 07:57:37 -05:00
2021-08-19 12:36:18 -05:00
app.post("/updateItem",(req,res)=>{
db.query("update crafting_list set obtained=$1 where id=$2",[req.body.obtained,req.body.id])
.then((data)=>{
return db.query("update site_data set last_modified=$1",[req.body.last_modified])
2021-07-23 05:02:52 -05:00
})
2021-08-19 12:36:18 -05:00
.then((data)=>{
res.status(200).send("Yay!")
})
.catch((err)=>{
res.status(500).send(err.message)
2021-07-12 08:49:47 -05:00
})
2021-08-07 13:17:07 -05:00
})
2021-08-19 12:36:18 -05:00
app.post('/setItem',(req,res)=>{
db.query('insert into crafting_list(itemid,name,obtained,required,icon) values($1,$2,$3,$4,$5)',[req.body.itemid,req.body.name,req.body.obtained,req.body.required,req.body.icon])
2021-08-12 06:26:01 +00:00
.then((data)=>{
2021-08-19 12:36:18 -05:00
res.status(200).send("Yay!")
2021-08-12 06:26:01 +00:00
})
.catch((err)=>{
res.status(500).send(err.message)
})
})