forked from digital-dream-labs/vector-web-setup
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.js
More file actions
70 lines (60 loc) · 2.69 KB
/
Copy pathserver.js
File metadata and controls
70 lines (60 loc) · 2.69 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"use strict";
const express = require("express");
require('dotenv').config()
const fs = require("fs");
const http = require("http");
const https = require("https");
const cors = require("cors");
const app = express();
let port = process.env.SERVER_PORT || 8000;
let otaport = process.env.OTA_SERVER_PORT || 8001;
let serverIp = "0.0.0.0"
var privateKey = fs.readFileSync( 'privkey.pem' );
var certificate = fs.readFileSync( 'privcert.pem' );
app.set("view engine", "ejs");
app.use("/", express.static('site'))
app.use(cors());
app.use(express.json()); // Used to parse JSON bodies
app.use(express.urlencoded({ extended: true })) // Parse URL-encoded bodies using query-string library
app.post("/sessions",(req,res)=>{
res.end('{"session":{"session_token":"2vMhFgktH3Jrbemm2WHkfGN","user_id":"2gsE4HbQ8UCBpYqurDgsafX","scope":"user","time_created":"2022-11-26T21:04:03.952175849Z","time_expires":"2123-11-26T21:04:03.952158558Z"},"user":{"user_id":"2gsE4HbQ8UCBpYqurDgsafX","drive_guest_id":"11ec68ca-1d4c-4e45-b1a2-715fd5e0abf9","player_id":"11ec68ca-1d4c-4e45-b1a2-715fd5e0abf9","created_by_app_name":"chewie","created_by_app_version":"1.0.2","created_by_app_platform":"android 8.0.0; samsung SM-G930U","dob":"2000-03-30","email":"whyyoulittle333@gmail.com","family_name":null,"gender":null,"given_name":null,"username":"whyyoulittle333@gmail.com","email_is_verified":true,"email_failure_code":null,"email_lang":"en-US","password_is_complex":true,"status":"active","time_created":"2018-10-21T05:06:41Z","deactivation_reason":null,"purge_reason":null,"email_is_blocked":false,"no_autodelete":false,"is_email_account":true}}');
})
function handleError(err){
switch (err.code) {
case "EADDRNOTAVAIL":
console.log(`Unable to bind to IP ${serverIp} on this device`);
return;
case "EACCES":
console.log(
`Permission denied to bind to IP ${serverIp} on PORT ${port} on this device.`
);
return;
case "EADDRINUSE":
console.log(
`Permission denied to bind to IP ${serverIp} on PORT ${port} on this device. The address is already in use.`
);
return;
default:
console.log(err);
return;
}
}
http.createServer(app).listen(port, serverIp, () => {
console.log(`Server running on port ${port}`);
}).on("error", (err) => {
handleError(err);
});
// https.createServer({
// key: privateKey,
// cert: certificate
// }, app).listen(port, serverIp, () => {
// console.log(`Server running on port ${port}`);
// }).on("error", (err) => {
// handleError(err);
// });
//This is used to serve the non http ota files
app.listen(otaport, serverIp, () => {
console.log(`OTA Server running on port ${otaport}`);
}).on("error", (err) => {
handleError(err);
});