/
githubmirror
/
angular
Обзор
Документация
Войти
/
githubmirror
/
angular
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
v21.2.16
packages/zone.js/simple-server.js
45 строк
1008 B
Joey Perrott
refactor: update license text to point to angular.dev (#57901)
24 сен 2024, 16:33
24 сен 2024, 16:33
9dbe6fc
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ const http = require('http'); const path = require('path'); const fs = require('fs'); let server; const localFolder = __dirname; function writeNotFound(res) { res.writeHead(404, {'Content-Type': 'text/html'}); res.end('<h1>404, Not Found!</h1>'); } function requestHandler(req, res) { if (req.url === '/close') { res.end('server closing'); setTimeout(() => { process.exit(0); }, 1000); } else { const file = path.resolve(localFolder, req.url); if (!file.startsWith(localFolder + '/')) { writeNotFound(res); return; } fs.readFile(file, function (err, contents) { if (!err) { res.end(contents); } else { writeNotFound(res); return; } }); } } server = http.createServer(requestHandler).listen(8080);