uiharu/uiharu.js

77 lines
1.8 KiB
JavaScript

const express = require('express');
const fs = require('fs');
const memcache = require('memcache-client');
const { join: pathJoin } = require('path');
// todo: these should not be hardcoded lol
const port = 3009;
const memcacheServer = "localhost:11211";
const allowedOrigins = [
'edgii.net',
'chat.edgii.net',
'sockchat.edgii.net',
'ajaxchat.edgii.net',
];
const app = express();
const isDebug = fs.existsSync(pathJoin(__dirname, '.debug'));
const cache = new memcache.MemcacheClient({ server: memcacheServer });
const handleMetadata = (res, req, url) => {
//
};
app.use((req, res, next) => {
res.set('X-Powered-By', 'Uiharu');
const origin = req.get('origin');
if(origin !== undefined) {
const originObj = new URL(origin);
if(!allowedOrigins.includes(originObj.host)) {
res.status(403).end();
return;
}
res.set('Access-Control-Allow-Origin', origin);
res.set('Vary', 'Origin');
}
if(req.method === 'OPTIONS')
res.set('Access-Control-Allow-Methods', 'OPTIONS, GET, POST');
next();
});
app.use(express.static('public'));
app.get('/metadata', (req, res) => {
res.status(501).send('Not Implemented');
});
app.post('/metadata', (req, res) => {
res.status(501).send('Not Implemented');
});
app.get('/metadata/batch', (req, res) => {
res.type('application/json')
.send('{"took":0,"results":[]}')
.end();
});
app.post('/metadata/batch', (req, res) => {
res.type('application/json')
.send('{"took":0,"results":[]}')
.end();
});
app.get('/metadata/thumb/audio', (req, res) => {
res.status(501).send('Not Implemented');
});
app.get('/metadata/thumb/video', (req, res) => {
res.status(501).send('Not Implemented');
});
app.listen(port, () => {
console.log(`Uiharu listening to port ${port}!`);
});