Use environtment variable to config API URL
This commit is contained in:
parent
b803beca10
commit
e3c74bb25e
13 changed files with 51 additions and 27 deletions
|
|
@ -8,6 +8,7 @@ node_modules
|
||||||
.eslintrc.cjs
|
.eslintrc.cjs
|
||||||
.prettierrc
|
.prettierrc
|
||||||
.pretieriignore
|
.pretieriignore
|
||||||
|
.env
|
||||||
README.md
|
README.md
|
||||||
Dockerfile
|
Dockerfile
|
||||||
docker-compose.yaml
|
docker-compose.yaml
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,9 @@ services:
|
||||||
# - "4025:80"
|
# - "4025:80"
|
||||||
environment:
|
environment:
|
||||||
TZ: Asia/Bangkok
|
TZ: Asia/Bangkok
|
||||||
|
API_CMS_URL: "https://bma-ehr-exam.frappet.synology.me/api/v1/cms"
|
||||||
|
API_QUALIFYING_URL: "https://bma-ehr-exam.frappet.synology.me/api/v1/cms"
|
||||||
|
API_COMPETITIVE_URL: "/api"
|
||||||
labels:
|
labels:
|
||||||
- traefik.enable=true
|
- traefik.enable=true
|
||||||
- traefik.http.routers.bma-ehr-qualifying-exam-cms.rule=Host(`bma-qualifying.frappet.synology.me`)
|
- traefik.http.routers.bma-ehr-qualifying-exam-cms.rule=Host(`bma-qualifying.frappet.synology.me`)
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,4 @@ export interface CMSInfo{
|
||||||
address:string;
|
address:string;
|
||||||
divisions:{title:string,url:string}[];
|
divisions:{title:string,url:string}[];
|
||||||
institutes:{title:string,url:string}[];
|
institutes:{title:string,url:string}[];
|
||||||
}
|
}
|
||||||
export const cmsBase="https://bma-ehr-exam.frappet.synology.me/api/v1/cms"
|
|
||||||
export const competitiveBase="/api"
|
|
||||||
export const qualifyingBase="https://bma-ehr-exam.frappet.synology.me/api/v1/cms"
|
|
||||||
|
|
@ -3,5 +3,5 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="p-10">
|
<div class="p-10">
|
||||||
<h1>{$page.error?.message}</h1>
|
<h1>{$page.status} {$page.error?.message}</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import {cmsBase} from '$lib/data/CMSDataType'
|
import { env } from '$env/dynamic/private'
|
||||||
import type { PageServerLoad } from './$types'
|
import type { PageServerLoad } from './$types'
|
||||||
export const load: PageServerLoad = async ({fetch}) => {
|
export const load: PageServerLoad = async ({fetch}) => {
|
||||||
const res = await fetch(cmsBase+"/home")
|
const res = await fetch(env.API_CMS_URL+"/home")
|
||||||
if(!res.ok)
|
if(!res.ok)
|
||||||
{
|
{
|
||||||
console.log("load offline data instead")
|
console.log("load offline data instead")
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,23 @@
|
||||||
import {cmsBase,qualifyingBase,competitiveBase} from '$lib/data/CMSDataType'
|
import { env } from '$env/dynamic/private'
|
||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
import type {Exam} from '$lib/data/CMSDataType'
|
import type {Exam} from '$lib/data/CMSDataType'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
export const load: PageServerLoad = async ({fetch}) => {
|
export const load: PageServerLoad = async ({fetch}) => {
|
||||||
let res = await fetch(cmsBase+"/home")
|
let res = await fetch(env.API_CMS_URL+"/home")
|
||||||
let info
|
let info
|
||||||
if(!res.ok)
|
if(!res.ok)
|
||||||
{
|
{
|
||||||
console.log("load offline CMS data instead")
|
console.log(res.status,"load offline CMS data instead")
|
||||||
info = (await import('$lib/data/info.json')).default
|
info = (await import('$lib/data/info.json')).default
|
||||||
}else{
|
}else{
|
||||||
info = await res.json()
|
info = await res.json()
|
||||||
}
|
}
|
||||||
const {title,subtitle} = info
|
const {title,subtitle} = info
|
||||||
|
|
||||||
res = await fetch(cmsBase+"/content/home")
|
res = await fetch(env.API_CMS_URL+"/content/home")
|
||||||
if(!res.ok){
|
if(!res.ok){
|
||||||
console.log("load offline home content instead")
|
console.log(res.status,"load offline home content instead")
|
||||||
const content = (await import('$lib/data/content/home.html?raw')).default
|
const content = (await import('$lib/data/content/home.html?raw')).default
|
||||||
info = {content,image:"/images/pattern.png"}
|
info = {content,image:"/images/pattern.png"}
|
||||||
}else{
|
}else{
|
||||||
|
|
@ -29,7 +29,8 @@ export const load: PageServerLoad = async ({fetch}) => {
|
||||||
async function loadExam(api_path:string,err_msg:string){
|
async function loadExam(api_path:string,err_msg:string){
|
||||||
const res = await fetch(api_path)
|
const res = await fetch(api_path)
|
||||||
if(!res.ok){
|
if(!res.ok){
|
||||||
throw error(500, err_msg);
|
console.log(res.status,err_msg,res.statusText)
|
||||||
|
throw error(res.status, err_msg);
|
||||||
}
|
}
|
||||||
const exams:Exam[] = await res.json()
|
const exams:Exam[] = await res.json()
|
||||||
exams.forEach((e)=>{
|
exams.forEach((e)=>{
|
||||||
|
|
@ -42,8 +43,8 @@ export const load: PageServerLoad = async ({fetch}) => {
|
||||||
}
|
}
|
||||||
return exams
|
return exams
|
||||||
}
|
}
|
||||||
const qualify_exams = loadExam(qualifyingBase+"/qualifying?limit=3",'ไม่สามารถอ่านรายการสอบคัดเลือกได้')
|
const qualify_exams = loadExam(env.API_QUALIFYING_URL +"/qualifying?limit=3",'ไม่สามารถอ่านรายการสอบคัดเลือกได้')
|
||||||
const competitive_exams = loadExam(competitiveBase+"/competitive?limit=3",'ไม่สามารถอ่านรายการสอบแข่งขันได้')
|
const competitive_exams = loadExam(env.API_COMPETITIVE_URL+"/competitive?limit=3",'ไม่สามารถอ่านรายการสอบแข่งขันได้')
|
||||||
|
|
||||||
return {title,subtitle,content,image, qualify_exams,competitive_exams };
|
return {title,subtitle,content,image, qualify_exams,competitive_exams };
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import {cmsBase} from '$lib/data/CMSDataType'
|
import { env } from '$env/dynamic/private'
|
||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
export const load = (async ({fetch}) => {
|
export const load = (async ({fetch}) => {
|
||||||
const res = await fetch(cmsBase+"/content/about")
|
const res = await fetch(env.API_CMS_URL+"/content/about")
|
||||||
if(!res.ok)
|
if(!res.ok)
|
||||||
throw error(500, 'ไม่สามารถอ่านเนื้อหาหน้าเกี่ยวกับได้');
|
throw error(500, 'ไม่สามารถอ่านเนื้อหาหน้าเกี่ยวกับได้');
|
||||||
const {content} = await res.json()
|
const {content} = await res.json()
|
||||||
|
|
|
||||||
23
cms/src/routes/api/content/[page]/+server.ts
Normal file
23
cms/src/routes/api/content/[page]/+server.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
import type { RequestEvent, RequestHandler } from './$types'
|
||||||
|
import {json} from '@sveltejs/kit'
|
||||||
|
export const GET: RequestHandler = async ({params}: RequestEvent) => {
|
||||||
|
let content = ""
|
||||||
|
let image
|
||||||
|
const page:string = params.page
|
||||||
|
switch (page) {
|
||||||
|
case "home":
|
||||||
|
content = (await import('$lib/data/content/home.html?raw')).default
|
||||||
|
image = "/images/pattern.png"
|
||||||
|
break;
|
||||||
|
case "qualifying":
|
||||||
|
content = (await import('$lib/data/content/qualifying.html?raw')).default
|
||||||
|
break;
|
||||||
|
case "competitive":
|
||||||
|
content = (await import('$lib/data/content/competitive.html?raw')).default
|
||||||
|
break;
|
||||||
|
case "about":
|
||||||
|
content = (await import('$lib/data/content/about.html?raw')).default
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return json({content,image})
|
||||||
|
}
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
import {competitiveBase} from '$lib/data/CMSDataType'
|
import { env } from '$env/dynamic/private'
|
||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
import type {CalendarEvent,Exam} from '$lib/data/CMSDataType'
|
import type {CalendarEvent,Exam} from '$lib/data/CMSDataType'
|
||||||
import {getBgColorDict} from '$lib/utils'
|
import {getBgColorDict} from '$lib/utils'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import type { PageServerLoad } from './$types'
|
import type { PageServerLoad } from './$types'
|
||||||
export const load: PageServerLoad = async ({fetch}) => {
|
export const load: PageServerLoad = async ({fetch}) => {
|
||||||
const res = await fetch(competitiveBase+"/competitive")
|
const res = await fetch(env.API_COMPETITIVE_URL+"/competitive")
|
||||||
if(!res.ok)
|
if(!res.ok)
|
||||||
throw error(res.status, 'ไม่สามารถอ่านข้อมูลการสอบได้');
|
throw error(res.status, 'ไม่สามารถอ่านข้อมูลการสอบได้');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
import {competitiveBase} from '$lib/data/CMSDataType'
|
import { env } from '$env/dynamic/private'
|
||||||
import type {Exam} from '$lib/data/CMSDataType'
|
import type {Exam} from '$lib/data/CMSDataType'
|
||||||
import { error } from '@sveltejs/kit'
|
import { error } from '@sveltejs/kit'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import type { PageServerLoad } from './$types'
|
import type { PageServerLoad } from './$types'
|
||||||
export const load: PageServerLoad = async ({params,fetch}) => {
|
export const load: PageServerLoad = async ({params,fetch}) => {
|
||||||
const id = params.id+""
|
const id = params.id+""
|
||||||
const res = await fetch(competitiveBase+"/competitive/"+id)
|
const res = await fetch(env.API_COMPETITIVE_URL+"/competitive/"+id)
|
||||||
if(res.status==404){
|
if(res.status==404){
|
||||||
throw error(404,{message:`ค้นหาข้อมูลสอบคัดเลือก ${id}ไม่พบ`})
|
throw error(404,{message:`ค้นหาข้อมูลสอบคัดเลือก ${id}ไม่พบ`})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
import {qualifyingBase} from '$lib/data/CMSDataType'
|
import { env } from '$env/dynamic/private'
|
||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
import type {CalendarEvent,Exam} from '$lib/data/CMSDataType'
|
import type {CalendarEvent,Exam} from '$lib/data/CMSDataType'
|
||||||
import {getBgColorDict} from '$lib/utils'
|
import {getBgColorDict} from '$lib/utils'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import type { PageServerLoad } from './$types'
|
import type { PageServerLoad } from './$types'
|
||||||
export const load: PageServerLoad = async ({fetch}) => {
|
export const load: PageServerLoad = async ({fetch}) => {
|
||||||
const res = await fetch(qualifyingBase+"/qualifying")
|
const res = await fetch(env.API_QUALIFYING_URL+"/qualifying")
|
||||||
if(!res.ok)
|
if(!res.ok)
|
||||||
throw error(res.status, 'ไม่สามารถอ่านข้อมูลการสอบได้');
|
throw error(res.status, 'ไม่สามารถอ่านข้อมูลการสอบได้');
|
||||||
const exams:Exam[] = await res.json()
|
const exams:Exam[] = await res.json()
|
||||||
|
|
@ -21,8 +21,7 @@ export const load: PageServerLoad = async ({fetch}) => {
|
||||||
const url = "/qualifying/"+id
|
const url = "/qualifying/"+id
|
||||||
if(start){
|
if(start){
|
||||||
ex.date = dayjs(start).format("DD MMM BBBB")
|
ex.date = dayjs(start).format("DD MMM BBBB")
|
||||||
console.log({id,title,start,end,url,backgroundColor})
|
events.push({id,title,start,end,url,backgroundColor})
|
||||||
events.push({id,title,start,url,backgroundColor})
|
|
||||||
}
|
}
|
||||||
if(ex.exam_date){
|
if(ex.exam_date){
|
||||||
events.push({id,"title":"วันสอบคัดเลือก","start":ex.exam_date,url,backgroundColor})
|
events.push({id,"title":"วันสอบคัดเลือก","start":ex.exam_date,url,backgroundColor})
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
import {qualifyingBase} from '$lib/data/CMSDataType'
|
import { env } from '$env/dynamic/private'
|
||||||
import type {Exam} from '$lib/data/CMSDataType'
|
import type {Exam} from '$lib/data/CMSDataType'
|
||||||
import { error } from '@sveltejs/kit'
|
import { error } from '@sveltejs/kit'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import type { PageServerLoad } from './$types'
|
import type { PageServerLoad } from './$types'
|
||||||
export const load: PageServerLoad = async ({params,fetch}) => {
|
export const load: PageServerLoad = async ({params,fetch}) => {
|
||||||
const id = params.id+""
|
const id = params.id+""
|
||||||
const res = await fetch(qualifyingBase+"/qualifying/"+id)
|
const res = await fetch(env.API_QUALIFYING_URL+"/qualifying/"+id)
|
||||||
if(res.status==404){
|
if(res.status==404){
|
||||||
throw error(404,{message:`ค้นหาข้อมูลสอบคัดเลือก ${id}ไม่พบ`})
|
throw error(404,{message:`ค้นหาข้อมูลสอบคัดเลือก ${id}ไม่พบ`})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue