diff --git a/client/pages/HomePage.tsx b/client/pages/HomePage.tsx index 1512c43..4c3f57f 100644 --- a/client/pages/HomePage.tsx +++ b/client/pages/HomePage.tsx @@ -27,7 +27,7 @@ const SORT_ORDER: Record = { export const HomePage = () => { const metadata = useContext(MetadataContext) metadata.title = `PHC Problemi` - metadata.description = 'Bacheca di problemi del PHC' + metadata.description = 'Bacheca di problemi di matematica creato dal PHC' const [problems] = useResource<(ProblemModel & { solutionsCount: number })[]>('/api/problems', []) diff --git a/index.html b/index.html index 0538193..1aa5984 100644 --- a/index.html +++ b/index.html @@ -21,11 +21,16 @@ - + + + + + + diff --git a/server.ts b/server.ts index 5969c36..b8643fe 100644 --- a/server.ts +++ b/server.ts @@ -33,7 +33,6 @@ async function createDevRouter() { }) r.use(vite.middlewares) - r.use('*', async (req, res, next) => { try { const indexHtml = await fs.readFile(path.resolve('./index.html'), 'utf-8') @@ -47,8 +46,12 @@ async function createDevRouter() { const fullUrl = `${req.protocol}://${req.get('host')}${req.originalUrl}` const metaTagsHtml = '' + - (metadata.title ? `\n` : '') + - (metadata.description ? `\n` : '') + + (metadata.title ? `\n` : '') + + (metadata.description + ? `\n` + : '') + `\n` res.send(transformedTemplate.replace('', metaTagsHtml).replace('', html)) @@ -69,26 +72,37 @@ async function createProductionRouter() { const r = express.Router() - r.use('/', express.static('dist/entry-client')) - - r.use('*', async (req, res) => { + const handleSSR = async (req, res) => { const transformedTemplate = await fs.readFile(path.resolve('./dist/entry-client/index.html'), 'utf-8') const { html, metadata } = render(req.originalUrl) + console.dir(transformedTemplate, { depth: null }) + console.dir(html, { depth: null }) + console.dir(metadata, { depth: null }) + const fullUrl = `${req.protocol}://${req.get('host')}${req.originalUrl}` const metaTagsHtml = '' + - (metadata.title ? `\n` : '') + + (metadata.title + ? `\n` + : `\n`) + (metadata.description - ? `\n` - : '') + + ? `\n` + : `\n`) + `\n` - res.send(transformedTemplate.replace('', metaTagsHtml).replace('', html)) - }) + const finalHtml = transformedTemplate.replace('', metaTagsHtml).replace('', html) + + console.dir(finalHtml, { depth: null }) + + res.send(finalHtml) + } + + r.get('/', handleSSR) + r.use('/', express.static('dist/entry-client')) + + r.use('*', handleSSR) return r } diff --git a/server/routes.ts b/server/routes.ts index 31b10ce..eb7045f 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -179,7 +179,7 @@ export async function createApiRouter() { } // uno studente può modificare solo il campo "content" - if (user.role === 'moderator' && !validateObjectKeys(req.body, ['content'])) { + if (user.role === 'moderator' && !validateObjectKeys(req.body, ['title', 'content'])) { res.status(StatusCodes.UNAUTHORIZED) res.send(`a moderator can only modify the field "content"`) return