added cors and title + description meta tags

This commit is contained in:
wukko 2022-07-10 20:04:03 +06:00
parent 9081f790ff
commit 22f13cc86f
4 changed files with 8 additions and 4 deletions

View file

@ -1,6 +1,7 @@
import "dotenv/config"
import express from "express";
import cors from "cors";
import * as fs from "fs";
import rateLimit from "express-rate-limit";
@ -16,6 +17,8 @@ import stream from "./modules/stream/stream.js";
const commitHash = currentCommit();
const app = express();
app.disable('x-powered-by');
if (fs.existsSync('./.env') && fs.existsSync('./config.json')) {
const apiLimiter = rateLimit({
windowMs: 20 * 60 * 1000,
@ -36,12 +39,10 @@ if (fs.existsSync('./.env') && fs.existsSync('./config.json')) {
}
})
app.set('etag', 'strong');
app.use('/api/', apiLimiter);
app.use('/api/stream', apiLimiterStream);
app.use('/', express.static('files'));
// avoid the %% URIError
app.use((req, res, next) => {
try {
decodeURIComponent(req.path)
@ -52,7 +53,7 @@ if (fs.existsSync('./.env') && fs.existsSync('./config.json')) {
next();
});
app.get('/api/:type', async (req, res) => {
app.get('/api/:type', cors({ origin: process.env.selfURL, optionsSuccessStatus: 200 }), async (req, res) => {
try {
switch (req.params.type) {
case 'json':

View file

@ -32,6 +32,8 @@ export default function(obj) {
<meta property="og:title" content="${appName}" />
<meta property="og:description" content="${loc(obj.lang, 'desc', 'embed')}" />
<meta property="og:image" content="${process.env.selfURL}icons/generic.png" />
<meta name="title" content="${appName}" />
<meta name="description" content="${loc(obj.lang, 'desc', 'embed')}" />
<meta name="theme-color" content="#000000" />
<meta name="twitter:card" content="summary" />

View file

@ -22,6 +22,7 @@
},
"homepage": "https://github.com/wukko/cobalt-web#readme",
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^16.0.1",
"express": "^4.17.1",
"express-rate-limit": "^6.3.0",

View file

@ -17,6 +17,6 @@
"liveVideo": "i can't download a live video. wait for stream to finish and try again.",
"nothingToDownload": "it seems like there's nothing to download. try another link!",
"cantConnectToAPI": "i couldn't connect to {s} api. seems like either {s} is down or server ip got blocked. try again later.",
"noStreamID": "there's no such stream id. you can't fool me!",
"noStreamID": "there's no such stream id.",
"noType": "there's no such expected response type."
}