2025-03-26 06:11:42 +09:00

44 lines
1.5 KiB
JavaScript

const http = require('http');
const { downloadContents, generateZipUrl } = require('./download/download');
const downloadFilesFromGCS = require('./download/gcsArchive');
const downloadFilesFromGCSJson = require('./download/gcsArchiveJson');
/**
* Create a new HTTP server
*/
const server = http.createServer((req, res) => {
// Set the response HTTP header with HTTP status and Content type
// root path
if (req.url === '/') {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
} else if (req.url === '/downdload') {
// ZIPファイルのコンテンツをそのまま返す
downloadContents(req, res);
} else if (req.url === '/generate-zip') {
// ZIPファイルの生成してストレージのURLを返す
generateZipUrl(req, res);
} else if (req.url === '/downdload-gcs') {
// GCSからZIPファイルのコンテンツをそのまま返す
downloadFilesFromGCS(req, res);
} else if (req.url === '/downdload-gcs-json') {
// GCSからZIPファイルのコンテンツをそのまま返す
downloadFilesFromGCSJson(req, res);
} else {
res.statusCode = 404;
res.setHeader('Content-Type', 'text/plain');
res.end('Not Found\n');
}
});
const port = 3000;
server.listen(port, () => {
console.log(`Server running at http://localhost:${port}/`);
});