Remove mime dependency
This commit is contained in:
parent
6caa38965c
commit
51dcfd4c21
12
package-lock.json
generated
12
package-lock.json
generated
@ -19,7 +19,6 @@
|
|||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
"json-rpc-2.0": "^1.4.1",
|
"json-rpc-2.0": "^1.4.1",
|
||||||
"memory-cache": "^0.2.0",
|
"memory-cache": "^0.2.0",
|
||||||
"mime": "^3.0.0",
|
|
||||||
"minecraft-ping-js": "^1.0.2",
|
"minecraft-ping-js": "^1.0.2",
|
||||||
"next": "^12.3.1",
|
"next": "^12.3.1",
|
||||||
"next-i18next": "^12.0.1",
|
"next-i18next": "^12.0.1",
|
||||||
@ -4167,17 +4166,6 @@
|
|||||||
"node": ">=8.6"
|
"node": ">=8.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/mime": {
|
|
||||||
"version": "3.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/mime/-/mime-3.0.0.tgz",
|
|
||||||
"integrity": "sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==",
|
|
||||||
"bin": {
|
|
||||||
"mime": "cli.js"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=10.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/mime-db": {
|
"node_modules/mime-db": {
|
||||||
"version": "1.52.0",
|
"version": "1.52.0",
|
||||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
||||||
|
|||||||
@ -21,7 +21,6 @@
|
|||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
"json-rpc-2.0": "^1.4.1",
|
"json-rpc-2.0": "^1.4.1",
|
||||||
"memory-cache": "^0.2.0",
|
"memory-cache": "^0.2.0",
|
||||||
"mime": "^3.0.0",
|
|
||||||
"minecraft-ping-js": "^1.0.2",
|
"minecraft-ping-js": "^1.0.2",
|
||||||
"next": "^12.3.1",
|
"next": "^12.3.1",
|
||||||
"next-i18next": "^12.0.1",
|
"next-i18next": "^12.0.1",
|
||||||
|
|||||||
@ -38,9 +38,6 @@ dependencies:
|
|||||||
memory-cache:
|
memory-cache:
|
||||||
specifier: ^0.2.0
|
specifier: ^0.2.0
|
||||||
version: 0.2.0
|
version: 0.2.0
|
||||||
mime:
|
|
||||||
specifier: ^3.0.0
|
|
||||||
version: 3.0.0
|
|
||||||
minecraft-ping-js:
|
minecraft-ping-js:
|
||||||
specifier: ^1.0.2
|
specifier: ^1.0.2
|
||||||
version: 1.0.2
|
version: 1.0.2
|
||||||
@ -2701,12 +2698,6 @@ packages:
|
|||||||
mime-db: 1.52.0
|
mime-db: 1.52.0
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/mime@3.0.0:
|
|
||||||
resolution: {integrity: sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==}
|
|
||||||
engines: {node: '>=10.0.0'}
|
|
||||||
hasBin: true
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/mimic-fn@2.1.0:
|
/mimic-fn@2.1.0:
|
||||||
resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==}
|
resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==}
|
||||||
engines: {node: '>=6'}
|
engines: {node: '>=6'}
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
|
||||||
import mime from "mime";
|
|
||||||
|
|
||||||
import { CONF_DIR } from "utils/config/config";
|
import { CONF_DIR } from "utils/config/config";
|
||||||
import createLogger from "utils/logger";
|
import createLogger from "utils/logger";
|
||||||
|
|
||||||
@ -15,18 +13,19 @@ const logger = createLogger("configFileService");
|
|||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
const { path: relativePath } = req.query;
|
const { path: relativePath } = req.query;
|
||||||
|
|
||||||
if(relativePath !== 'custom.js' && relativePath !== 'custom.css')
|
// only two supported files, for now
|
||||||
|
if (!['custom.css', 'custom.js'].includes(relativePath))
|
||||||
{
|
{
|
||||||
res.status(422).end('Incorrect file extension, expected custom.js or custom.css')
|
res.status(422).end('Unsupported file')
|
||||||
}
|
}
|
||||||
|
|
||||||
const filePath = path.join(CONF_DIR, relativePath);
|
const filePath = path.join(CONF_DIR, relativePath);
|
||||||
const mimeType = mime.getType(relativePath);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Read the content of the file or return empty content
|
// Read the content of the file or return empty content
|
||||||
const fileContent = fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf-8') : '';
|
const fileContent = fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf-8') : '';
|
||||||
|
// hard-coded since we only support two known files for now
|
||||||
|
const mimeType = (relativePath === 'custom.css') ? 'text/css' : 'text/javascript';
|
||||||
res.setHeader('Content-Type', mimeType);
|
res.setHeader('Content-Type', mimeType);
|
||||||
res.status(200).send(fileContent);
|
res.status(200).send(fileContent);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user