Код IT
← Каталог

Dockerfile — 10 типовых образов — 3. Node.js API (Express / Fastify)

Фрагмент из «Dockerfile — 10 типовых образов»: 3. Node.js API (Express / Fastify).

JavaScript part-01.js
const http = require('http');

const server = http.createServer((req, res) => {
  if (req.url === '/health') {
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end('ok');
    return;
  }
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Node API в Docker работает\n');
});

// 0.0.0.0 — слушать все интерфейсы; иначе с хоста не достучаться
server.listen(3000, '0.0.0.0', () => {
  console.log('Слушаю http://0.0.0.0:3000');
});
const http = require('http');

const server = http.createServer((req, res) => {
  if (req.url === '/health') {
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end('ok');
    return;
  }
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Node API в Docker работает\n');
});

// 0.0.0.0 — слушать все интерфейсы; иначе с хоста не достучаться
server.listen(3000, '0.0.0.0', () => {
  console.log('Слушаю http://0.0.0.0:3000');
});