32 lines
936 B
JavaScript
32 lines
936 B
JavaScript
import request from 'request';
|
|
import express from 'express';
|
|
import ssr from './ssr.js';
|
|
import { port, host, forumsHost } from './config.js';
|
|
|
|
const app = express()
|
|
|
|
app.get('/api/*', async (req, res) => {
|
|
request(`${host}${req.url}`).pipe(res);
|
|
});
|
|
|
|
app.get('/react/build/*', async (req, res) => {
|
|
request(`${host}${req.url}`).pipe(res);
|
|
});
|
|
|
|
app.get('/images/*', async (req, res) => {
|
|
request(`${host}${req.url}`).pipe(res);
|
|
});
|
|
|
|
app.get('/system/lets/*', async (req, res) => {
|
|
request(`${host}${req.url}`).pipe(res);
|
|
});
|
|
|
|
app.get('*', async (req, res) => {
|
|
const {html, ttRenderMs} = await ssr(`${req.originalUrl.includes('forums') ? forumsHost : host}${req.originalUrl}`);
|
|
res.set('Server-Timing', `Prerender;dur=${ttRenderMs};desc="Headless render time (ms)"`);
|
|
return res.status(200).send(html); // Serve prerendered page as response.
|
|
});
|
|
|
|
app.listen(port, () => {
|
|
console.log(`app listening on port ${port}`)
|
|
}) |