Added home and charts pages
This commit is contained in:
@@ -6,7 +6,6 @@ import initDebug from 'debug'
|
||||
import { registerMiddlewares } from './middlewares'
|
||||
|
||||
import indexRouter from './routes'
|
||||
import usersRouter from './routes/users'
|
||||
|
||||
import { normalizePort } from './helpers/port'
|
||||
import { getErrorCb, getListeningCb } from './helpers/server-callbacks'
|
||||
@@ -24,7 +23,6 @@ registerMiddlewares(app)
|
||||
|
||||
/* === Routes === */
|
||||
app.use('/', indexRouter)
|
||||
app.use('/users', usersRouter)
|
||||
|
||||
/* === APIs === */
|
||||
registerApis(app)
|
||||
|
||||
31
server/src/main.ts
Normal file
31
server/src/main.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
// @ts-ignore
|
||||
import { Deezer } from 'deezer-js'
|
||||
|
||||
console.log("init!")
|
||||
const dz = new Deezer()
|
||||
let homeCache: any, chartsCache: any
|
||||
|
||||
export async function getHome(){
|
||||
if (!homeCache){
|
||||
homeCache = await dz.api.get_chart(0, {limit: 30})
|
||||
}
|
||||
return homeCache
|
||||
}
|
||||
|
||||
export async function getCharts(){
|
||||
if (!chartsCache){
|
||||
const chartsData = await dz.api.get_countries_charts()
|
||||
let countries: any[] = []
|
||||
chartsData.forEach((country: any) => {
|
||||
countries.push({
|
||||
title: country.title.replace("Top ", ""),
|
||||
id: country.id,
|
||||
picture_small: country.picture_small,
|
||||
picture_medium: country.picture_medium,
|
||||
picture_big: country.picture_big,
|
||||
})
|
||||
})
|
||||
chartsCache = {data: countries}
|
||||
}
|
||||
return chartsCache
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { ApiHandler } from '../../../types'
|
||||
import { getCharts } from '../../../main'
|
||||
|
||||
const path: ApiHandler['path'] = '/getCharts'
|
||||
|
||||
const handler: ApiHandler['handler'] = async (_, res) => {
|
||||
const chartsData = await getCharts()
|
||||
res.send(chartsData)
|
||||
}
|
||||
|
||||
const apiHandler: ApiHandler = { path, handler }
|
||||
|
||||
export default apiHandler
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { ApiHandler } from '../../../types'
|
||||
import { getHome } from '../../../main'
|
||||
|
||||
const path: ApiHandler['path'] = '/getHome'
|
||||
|
||||
const handler: ApiHandler['handler'] = (_, res) => {
|
||||
res.send('getHome')
|
||||
const handler: ApiHandler['handler'] = async (_, res) => {
|
||||
const homeData = await getHome()
|
||||
res.send(homeData)
|
||||
}
|
||||
|
||||
const apiHandler: ApiHandler = { path, handler }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import sample from './sample'
|
||||
import getHome from './getHome'
|
||||
import getCharts from './getCharts'
|
||||
|
||||
export default [sample, getHome]
|
||||
export default [sample, getHome, getCharts]
|
||||
|
||||
@@ -8,7 +8,7 @@ const router = express.Router()
|
||||
* @since 0.0.0
|
||||
*/
|
||||
router.get('/', (_, res) => {
|
||||
res.render('index', { title: 'Express' })
|
||||
res.render('index', { title: 'deemix' })
|
||||
})
|
||||
|
||||
export default router
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
import express from 'express'
|
||||
|
||||
const router = express.Router()
|
||||
|
||||
/**
|
||||
* GET users listing.
|
||||
*
|
||||
* @since 0.0.0
|
||||
*/
|
||||
router.get('/', (_, res) => {
|
||||
res.send('respond with a resource')
|
||||
})
|
||||
|
||||
export default router
|
||||
Reference in New Issue
Block a user