Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Neo-Zhixing committed May 31, 2020
1 parent 85e7e84 commit ea03db4
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const http = require('http');
const https = require('https');
const
{
URL
Expand All @@ -10,17 +9,6 @@ const gm = require('gm').subClass(
imageMagick: true
});

const bucketName = process.env.BUCKET_NAME || 'assets.cytoid.io';

function requestURLForPath(url)
{
let path = url.pathname;
if (path.startsWith('/'))
{
path = path.substr(1);
}
return `https://www.googleapis.com/storage/v1/b/${bucketName}/o/${encodeURIComponent(path)}?alt=media`;
}

function requestListener(req, res)
{
Expand All @@ -32,8 +20,13 @@ function requestListener(req, res)
res.end('Method not allowed');
}
const url = new URL(req.url, 'https://images.cytoid.io');
const request = https.get(requestURLForPath(url), (response) =>
{
const request = http.get({
host: 'c.storage.googleapis.com',
path: url.pathname,
headers: {
'Host': 'assets.cytoid.io',
}
}, (response) => {
if (response.statusCode === 200)
{
// Image exists.
Expand Down

0 comments on commit ea03db4

Please sign in to comment.