Add integration with api for static pages

This commit is contained in:
Kacper Donat 2020-09-17 21:02:27 +02:00
parent 25d876d221
commit fa04dd26cc
4 changed files with 50 additions and 24 deletions

40
src/api/dto/page.ts Normal file
View File

@ -0,0 +1,40 @@
import { Identifiable } from "@/data";
import { Page } from "@/data/page";
import { Transformer } from "@/serialization";
export interface PageDTO extends Identifiable {
accessName: string;
title: string;
titleEng: string;
content: string;
contentEng: string;
}
export const pageDtoTransformer: Transformer<PageDTO, Page> = {
reverseTransform(subject: Page, context: undefined): PageDTO {
return {
id: subject.id,
accessName: subject.slug,
content: subject.content.pl,
contentEng: subject.content.en,
title: subject.title.pl,
titleEng: subject.title.en,
}
},
transform(subject: PageDTO, context: undefined): Page {
return {
slug: subject.accessName,
id: subject.id,
content: {
pl: subject.content,
en: subject.contentEng
},
title: {
pl: subject.title,
en: subject.titleEng
},
};
}
}
export default pageDtoTransformer;

View File

@ -1,27 +1,13 @@
// MOCK
import { Page } from "@/data/page";
import { PageDTO, pageDtoTransformer } from "./dto/page"
import { axios } from "@/api/index";
import { prepare } from "@/routing";
const tos = `<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Bestiarum vero nullum iudicium puto. Quare ad ea primum, si videtur; <b>Duo Reges: constructio interrete.</b> <i>Eam tum adesse, cum dolor omnis absit;</i> Sed ad bona praeterita redeamus. <mark>Facillimum id quidem est, inquam.</mark> Apud ceteros autem philosophos, qui quaesivit aliquid, tacet; </p>
<p><a href="http://loripsum.net/" target="_blank">Quorum altera prosunt, nocent altera.</a> Eam stabilem appellas. <i>Sed nimis multa.</i> Quo plebiscito decreta a senatu est consuli quaestio Cn. Sin laboramus, quis est, qui alienae modum statuat industriae? <mark>Quod quidem nobis non saepe contingit.</mark> Si autem id non concedatur, non continuo vita beata tollitur. <a href="http://loripsum.net/" target="_blank">Illum mallem levares, quo optimum atque humanissimum virum, Cn.</a> <i>Id est enim, de quo quaerimus.</i> </p>
<p>Ille vero, si insipiens-quo certe, quoniam tyrannus -, numquam beatus; Sin dicit obscurari quaedam nec apparere, quia valde parva sint, nos quoque concedimus; Et quod est munus, quod opus sapientiae? Ab hoc autem quaedam non melius quam veteres, quaedam omnino relicta. </p>
`
const STATIC_PAGE_ENDPOINT = "/staticPage/:slug"
export async function get(slug: string): Promise<Page> {
if (slug === "/regulamin" || slug === "/rules") {
return {
id: "tak",
content: {
pl: tos,
en: tos,
},
title: {
pl: "Regulamin Praktyk",
en: "Terms of Internship",
},
}
}
const response = await axios.get<PageDTO>(prepare(STATIC_PAGE_ENDPOINT, { slug }))
const page = response.data;
throw new Error();
return pageDtoTransformer.transform(page);
}

View File

@ -3,4 +3,5 @@ import { Identifiable, Multilingual } from "@/data/common";
export interface Page extends Identifiable {
title: Multilingual<string>;
content: Multilingual<string>;
slug: string;
}

View File

@ -51,12 +51,11 @@ const config = {
],
devServer: {
contentBase: path.resolve("./public/"),
port: 443,
host: 'system-praktyk.stg.kadet.net',
host: process.env.APP_HOST || 'system-praktyk-front.localhost',
disableHostCheck: true,
historyApiFallback: true,
overlay: true,
https: true,
https: !!process.env.APP_HTTPS || false,
proxy: {
"/api": {
target: "http://system-praktyk-front.localhost:8080/",