/
setwind
/
City
Обзор
Документация
Войти
/
setwind
/
City
Код
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
frontend/src/server.ts
66 строк
2 KB
InfinityExistence
add fronted and isAuthenticated
19 май 2025, 11:16
19 май 2025, 11:16
697ae4c
Код
Авторство
О чём код?
import { AngularNodeAppEngine, createNodeRequestHandler, isMainModule, writeResponseToNodeResponse, } from '@angular/ssr/node'; import express from 'express'; import {dirname, resolve} from 'node:path'; import {fileURLToPath} from 'node:url'; const serverDistFolder = dirname(fileURLToPath(import.meta.url)); const browserDistFolder = resolve(serverDistFolder, '../browser'); const app = express(); const angularApp = new AngularNodeAppEngine(); /** * Example Express Rest API endpoints can be defined here. * Uncomment and define endpoints as necessary. * * Example: * ```ts * app.get('/api/**', (req, res) => { * // Handle API request * }); * ``` */ /** * Serve static files from /browser */ app.use( express.static(browserDistFolder, { maxAge: '1y', index: false, redirect: false, }), ); /** * Handle all other requests by rendering the Angular application. */ app.use('/**', (req, res, next) => { angularApp .handle(req) .then((response) => response ? writeResponseToNodeResponse(response, res) : next(), ) .catch(next); }); /** * Start the server if this module is the main entry point. * The server listens on the port defined by the `PORT` environment variable, or defaults to 4000. */ if (isMainModule(import.meta.url)) { const port: number = (process.env['PORT'] || 4000) as number; app.listen(port, "0.0.0.0", () => { console.log(`Node Express server listening on http://localhost:${port}`); }); } /** * Request handler used by the Angular CLI (for dev-server and during build) or Firebase Cloud Functions. */ export const reqHandler = createNodeRequestHandler(app);