Compare commits
2 Commits
042648512f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
093007bc76 | ||
|
|
5001b8203d |
@@ -2,7 +2,6 @@
|
|||||||
import postgres from 'postgres';
|
import postgres from 'postgres';
|
||||||
import 'dotenv/config'
|
import 'dotenv/config'
|
||||||
|
|
||||||
console.log("url: ", process.env.LOCAL_DATABASE_URL)
|
const sql = postgres(process.env.DATABASE_URL);
|
||||||
const sql = postgres(process.env.LOCAL_DATABASE_URL);
|
|
||||||
|
|
||||||
export default sql;
|
export default sql;
|
||||||
@@ -38,7 +38,6 @@ class Server {
|
|||||||
|
|
||||||
/* Site */
|
/* Site */
|
||||||
router.post('/free', this.newUserSubmission)
|
router.post('/free', this.newUserSubmission)
|
||||||
router.get('/db/images/*', this.getUserImage)
|
|
||||||
router.get('/api/orgdata/*', this.getOrgData)
|
router.get('/api/orgdata/*', this.getOrgData)
|
||||||
router.get('/api/mydata/*', this.getPersonalData)
|
router.get('/api/mydata/*', this.getPersonalData)
|
||||||
router.get('/*', this.get)
|
router.get('/*', this.get)
|
||||||
@@ -135,25 +134,6 @@ class Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getUserImage = async (req, res) => {
|
|
||||||
function getFileByNumber(dir, number) {
|
|
||||||
const files = fs.readdirSync(dir);
|
|
||||||
const match = files.find(file => {
|
|
||||||
const base = path.parse(file).name; // filename without extension
|
|
||||||
return base === String(number);
|
|
||||||
});
|
|
||||||
return match ? path.join(dir, match) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
let filePath = path.join(this.DBPath, "images", path.basename(req.url))
|
|
||||||
|
|
||||||
if(filePath) {
|
|
||||||
res.sendFile(filePath)
|
|
||||||
} else {
|
|
||||||
return res.status(404).json({error: "Can't find image"})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
get = async (req, res) => {
|
get = async (req, res) => {
|
||||||
|
|
||||||
let url = req.url
|
let url = req.url
|
||||||
@@ -178,6 +158,8 @@ class Server {
|
|||||||
filePath = path.join(this.UIPath, url);
|
filePath = path.join(this.UIPath, url);
|
||||||
} else if(url.includes("75820185")) {
|
} else if(url.includes("75820185")) {
|
||||||
filePath = path.join(this.UIPath, platformFolder, url.split("75820185")[1]);
|
filePath = path.join(this.UIPath, platformFolder, url.split("75820185")[1]);
|
||||||
|
} else if(url.startsWith("/db")) {
|
||||||
|
filePath = path.join(this.DBPath, url.replace('/db', ''));
|
||||||
} else {
|
} else {
|
||||||
filePath = path.join(this.UIPath, platformFolder, "index.html");
|
filePath = path.join(this.UIPath, platformFolder, "index.html");
|
||||||
}
|
}
|
||||||
@@ -245,7 +227,7 @@ class Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
async init() {
|
||||||
this.db = new Database()
|
this.db = new Database()
|
||||||
this.auth = new AuthHandler()
|
this.auth = new AuthHandler()
|
||||||
global.db = this.db
|
global.db = this.db
|
||||||
@@ -285,7 +267,7 @@ class Server {
|
|||||||
app.use(this.logRequest);
|
app.use(this.logRequest);
|
||||||
app.use(this.logResponse);
|
app.use(this.logResponse);
|
||||||
|
|
||||||
this.mountApps(app)
|
await this.mountApps(app) // must be completed before router is registered
|
||||||
|
|
||||||
let router = express.Router();
|
let router = express.Router();
|
||||||
this.registerRoutes(router)
|
this.registerRoutes(router)
|
||||||
@@ -310,6 +292,10 @@ class Server {
|
|||||||
|
|
||||||
Object.preventExtensions(this);
|
Object.preventExtensions(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.init()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const server = new Server()
|
const server = new Server()
|
||||||
@@ -29,6 +29,7 @@
|
|||||||
--accent: rgb(57, 26, 0);
|
--accent: rgb(57, 26, 0);
|
||||||
--accent2: rgb(57, 26, 0);
|
--accent2: rgb(57, 26, 0);
|
||||||
--window: #ffc28b;
|
--window: #ffc28b;
|
||||||
|
--divider: rgb(205 152 76);
|
||||||
|
|
||||||
--house-src: /_/icons/house.svg;
|
--house-src: /_/icons/house.svg;
|
||||||
--nodes-src: /_/icons/nodes.svg;
|
--nodes-src: /_/icons/nodes.svg;
|
||||||
|
|||||||
Reference in New Issue
Block a user