mirror of
https://github.com/rikkaneko/paste.git
synced 2025-08-07 06:25:33 +01:00
Fix js/css content type (paste)
Update README.md Signed-off-by: Joe Ma <rikkaneko23@gmail.com>
This commit is contained in:
parent
7e65c403f7
commit
0f89088486
3 changed files with 28 additions and 41 deletions
65
src/index.ts
65
src/index.ts
|
@ -69,54 +69,18 @@ export default {
|
|||
}
|
||||
|
||||
if (path === '/v1' && method == 'GET') {
|
||||
return await fetch(PASTE_WEB_URL_v1 + '/paste.html', {
|
||||
cf: {
|
||||
cacheEverything: true,
|
||||
},
|
||||
}).then(value => {
|
||||
return new Response(value.body, {
|
||||
// Add the correct content-type to response header
|
||||
headers: {
|
||||
'content-type': 'text/html; charset=UTF-8;',
|
||||
'cache-control': 'public, max-age=172800',
|
||||
},
|
||||
});
|
||||
});
|
||||
return await proxy_uri(PASTE_WEB_URL_v1 + '/paste.html');
|
||||
}
|
||||
|
||||
if (/\/(js|css)\/.*$/.test(path) && method == 'GET') {
|
||||
return await fetch(PASTE_WEB_URL + path, {
|
||||
cf: {
|
||||
cacheEverything: true,
|
||||
},
|
||||
}).then(value => {
|
||||
return new Response(value.body, {
|
||||
// Add the correct content-type to response header
|
||||
headers: {
|
||||
'content-type': 'text/html; charset=UTF-8;',
|
||||
'cache-control': 'public, max-age=172800',
|
||||
},
|
||||
});
|
||||
});
|
||||
return await proxy_uri(PASTE_WEB_URL + path);
|
||||
}
|
||||
|
||||
if (path === '/') {
|
||||
switch (method) {
|
||||
// Fetch the HTML for uploading text/file
|
||||
case 'GET': {
|
||||
return await fetch(PASTE_WEB_URL + '/paste.html', {
|
||||
cf: {
|
||||
cacheEverything: true,
|
||||
},
|
||||
}).then(value => {
|
||||
return new Response(value.body, {
|
||||
// Add the correct content-type to response header
|
||||
headers: {
|
||||
'content-type': 'text/html; charset=UTF-8;',
|
||||
'cache-control': 'public, max-age=172800',
|
||||
},
|
||||
});
|
||||
});
|
||||
// Fetch the HTML for uploading text/file
|
||||
return await proxy_uri(PASTE_WEB_URL + '/paste.html');
|
||||
}
|
||||
|
||||
// Create new paste
|
||||
|
@ -636,6 +600,27 @@ function to_human_readable_size(bytes: number): string {
|
|||
return size;
|
||||
}
|
||||
|
||||
// Proxy URI (limit to html/js/css)
|
||||
async function proxy_uri(path: string, cf: RequestInitCfProperties = {cacheEverything: true}) {
|
||||
// Fix content type
|
||||
let file_type = 'text/plain';
|
||||
if (path.endsWith('.js')) file_type = 'application/javascript';
|
||||
if (path.endsWith('.css')) file_type = 'text/css';
|
||||
if (path.endsWith('.html')) file_type = 'text/html';
|
||||
|
||||
return await fetch(path, {
|
||||
cf,
|
||||
}).then(value => {
|
||||
return new Response(value.body, {
|
||||
// Add the correct content-type to response header
|
||||
headers: {
|
||||
'content-type': `${file_type}; charset=UTF-8;`,
|
||||
'cache-control': 'public, max-age=172800',
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
interface PasteIndexEntry {
|
||||
title?: string,
|
||||
mime_type?: string,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue