oops
This commit is contained in:
101
api/server.js.save
Normal file
101
api/server.js.save
Normal file
@@ -0,0 +1,101 @@
|
||||
const express = require("express");
|
||||
const bodyParser = require("body-parser");
|
||||
const cors = require("cors");
|
||||
const fs = require("fs");
|
||||
const wol = require("wol");
|
||||
|
||||
try {
|
||||
var links = require('../src/links.json');
|
||||
} catch(err) {
|
||||
let body = `{
|
||||
"bookmarks" : [
|
||||
{
|
||||
"category": "Example",
|
||||
"links": [
|
||||
{
|
||||
"name": "Gitea",
|
||||
"url": "https://home.halfaperture.com/gitea"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}`;
|
||||
fs.writeFileSync('../src/links.json',body);
|
||||
var links = require('../src/links.json');
|
||||
}
|
||||
|
||||
try {
|
||||
var personaldata = require('../src/personaldata.json');
|
||||
} catch(err) {
|
||||
let body = `{
|
||||
"fname":"",
|
||||
"lname":"",
|
||||
"email":""
|
||||
}`;
|
||||
fs.writeFileSync('../src/personaldata.json',body);
|
||||
var personaldata = require('../src/personaldata.json');
|
||||
}
|
||||
|
||||
if (fs.existsSync('../src/apps.json')) {
|
||||
console.log("apps.json exists");
|
||||
}else {
|
||||
let body = `{
|
||||
"apps" : [
|
||||
{"name":"Example","url":"your.site.com/example","icon":"web","urlbase":"/Example","NSFW":"SAFE"}
|
||||
]
|
||||
}`;
|
||||
fs.writeFileSync('../src/apps.json',body);
|
||||
}
|
||||
|
||||
const providers = require('../src/providers.json');
|
||||
const themes = require('../src/themes.json');
|
||||
const messages = require('../src/messages.json');
|
||||
|
||||
// initializing app
|
||||
const app = express();
|
||||
|
||||
// initializing cors middleware for all routes
|
||||
app.use(cors());
|
||||
var jsonParser = bodyParser.json();
|
||||
|
||||
// creating route to make request to server for API
|
||||
app.get("/sui/api/apps", (req, res) => {
|
||||
fs.readFile('../src/apps.json', (err, data) => {
|
||||
if (err) throw err;
|
||||
let apps = JSON.parse(data);
|
||||
res.status(200).send(apps.apps);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
app.get("/sui/api/links", (req, res) => {
|
||||
res.status(200).send(links.bookmarks);
|
||||
});
|
||||
|
||||
app.get("/sui/api/providers", (req, res) => {
|
||||
res.status(200).send(providers.providers);
|
||||
});
|
||||
|
||||
app.get("/sui/api/themes", (req, res) => {
|
||||
res.status(200).send(themes.themes);
|
||||
});
|
||||
|
||||
app.get("/sui/api/personaldata", (req, res) => {
|
||||
res.status(200).send(personaldata);
|
||||
});
|
||||
|
||||
app.get("/sui/api/messages", (req, res) => {
|
||||
res.status(200).send(messages.messages);
|
||||
});
|
||||
|
||||
app.post("/sui/api/appUpdate", jsonParser, (req, res) => {
|
||||
let data = JSON.stringify(req.body)
|
||||
fs.writeFileSync('../src/apps.json',data)
|
||||
var applications = require('../src/apps.json');
|
||||
res.status(200).send(applications.apps)
|
||||
});
|
||||
|
||||
app.post("/sui/api/wakeDakota", (req, res) => { wol.wake('18:C0:4D:81:57:68', function(err, res){ console.log(res);// app is listening on port 5000
|
||||
});app.listen(5000, () => {
|
||||
}); console.log("node server is running on port 5000");
|
||||
});
|
||||
Reference in New Issue
Block a user