Добавлен сервер на Express для обслуживания статических файлов и главной страницы

This commit is contained in:
kromskii2 committed 2025-01-05 11:56:47 +07:00
1 parent b7d803c5aa
commit a72c50945f
1 file changed
+19
+19
View File
@@ -0,0 +1,19 @@
const express = require('express');
const path = require('path');
const app = express();
const PORT = 3000;
// Middleware для обслуживания статических файлов из папки "src" и корня приложения
app.use('/src', express.static(path.join(__dirname, 'src')));
app.use('/', express.static(path.join(__dirname, '')));
// Главная страница
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
});
// Запуск сервера
app.listen(PORT, '0.0.0.0', () => {
console.log(`Server is running on http://0.0.0.0:${PORT}`);
});