Use environtment variable to config API URL

This commit is contained in:
schooltechx 2023-04-10 17:58:14 +07:00
parent b803beca10
commit e3c74bb25e
13 changed files with 51 additions and 27 deletions

View file

@ -1,11 +1,11 @@
import {qualifyingBase} from '$lib/data/CMSDataType'
import { env } from '$env/dynamic/private'
import { error } from '@sveltejs/kit';
import type {CalendarEvent,Exam} from '$lib/data/CMSDataType'
import {getBgColorDict} from '$lib/utils'
import dayjs from 'dayjs'
import type { PageServerLoad } from './$types'
export const load: PageServerLoad = async ({fetch}) => {
const res = await fetch(qualifyingBase+"/qualifying")
const res = await fetch(env.API_QUALIFYING_URL+"/qualifying")
if(!res.ok)
throw error(res.status, 'ไม่สามารถอ่านข้อมูลการสอบได้');
const exams:Exam[] = await res.json()
@ -21,8 +21,7 @@ export const load: PageServerLoad = async ({fetch}) => {
const url = "/qualifying/"+id
if(start){
ex.date = dayjs(start).format("DD MMM BBBB")
console.log({id,title,start,end,url,backgroundColor})
events.push({id,title,start,url,backgroundColor})
events.push({id,title,start,end,url,backgroundColor})
}
if(ex.exam_date){
events.push({id,"title":"วันสอบคัดเลือก","start":ex.exam_date,url,backgroundColor})

View file

@ -1,11 +1,11 @@
import {qualifyingBase} from '$lib/data/CMSDataType'
import { env } from '$env/dynamic/private'
import type {Exam} from '$lib/data/CMSDataType'
import { error } from '@sveltejs/kit'
import dayjs from 'dayjs'
import type { PageServerLoad } from './$types'
export const load: PageServerLoad = async ({params,fetch}) => {
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){
throw error(404,{message:`ค้นหาข้อมูลสอบคัดเลือก ${id}ไม่พบ`})
}