76 lines
2.2 KiB
TypeScript
76 lines
2.2 KiB
TypeScript
import express, {Express} from 'express';
|
|
import cors from 'cors';
|
|
import queueRoutes from "./routes/queue.routes";
|
|
import bodyParser from 'body-parser';
|
|
import pingRoutes from "./routes/ping.routes";
|
|
import queueManager from "./queueManager";
|
|
import {DEFAULT_LUCIDA_OPTIONS} from "./types/queue";
|
|
|
|
const app: Express = express();
|
|
|
|
app.use(cors());
|
|
app.use(express.json());
|
|
app.use(bodyParser.urlencoded({extended: true}));
|
|
|
|
/* Routes */
|
|
app.use('/api/v1/ping', pingRoutes);
|
|
app.use('/api/v1/queue', queueRoutes);
|
|
|
|
/* Setup */
|
|
let port: number = 3000;
|
|
let baseUrl: string = DEFAULT_LUCIDA_OPTIONS.baseUrl;
|
|
let headless: boolean = DEFAULT_LUCIDA_OPTIONS.headless;
|
|
let proxy: string | undefined = DEFAULT_LUCIDA_OPTIONS.proxy;
|
|
|
|
// Parse command line arguments
|
|
let i: number = 0;
|
|
while (i < process.argv.length) {
|
|
switch (process.argv[i]) {
|
|
case '--port':
|
|
i++;
|
|
port = parseInt(process.argv[i]);
|
|
break;
|
|
case '--lucida':
|
|
i++;
|
|
baseUrl = process.argv[i];
|
|
break;
|
|
case '--headless':
|
|
i++;
|
|
headless = process.argv[i] === 'true';
|
|
break;
|
|
case '--proxy':
|
|
i++;
|
|
proxy = process.argv[i];
|
|
break;
|
|
case '--help':
|
|
console.log(`
|
|
Options:
|
|
--port Specify the port to run the server on. Default is 3000.
|
|
--lucida Specify the url to the Lucida server. Default is 'https://lucida.to/'
|
|
--headless Run the Lucida browser in headless mode.
|
|
--proxy Specify a proxy to use for requests. Example: --proxy 'socks5://localhost:9050' (Tor)
|
|
--help Show this help message and exit.
|
|
`);
|
|
process.exit();
|
|
default:
|
|
console.error(`App: Unknown option ${process.argv[i]}`);
|
|
break;
|
|
}
|
|
i++;
|
|
}
|
|
const lucidaOptions = {
|
|
baseUrl: baseUrl,
|
|
headless: headless,
|
|
proxy: proxy
|
|
};
|
|
queueManager.setLucidaOptions(lucidaOptions);
|
|
|
|
process.on('SIGINT', async () => {
|
|
console.log('App: Received SIGINT');
|
|
await queueManager.forceStop();
|
|
process.exit();
|
|
});
|
|
|
|
app.listen(port, () => {
|
|
console.log(`App: Server running on port ${port}`);
|
|
});
|