docs: 🔥 added netlify

This commit is contained in:
Leifer Mendez
2022-12-28 20:51:28 +01:00
parent 5b796a163e
commit be39e8fd30
14 changed files with 7644 additions and 832 deletions

View File

@@ -1,8 +1,12 @@
import { component$ } from '@builder.io/qwik'
import { RequestHandlerCloudflarePages } from '@builder.io/qwik-city/middleware/cloudflare-pages'
import { User } from '~/contexts'
import Collaborator from './Collaborator'
export const onRequest: RequestHandlerCloudflarePages = async () => {
console.log('??heree')
}
export const TaleUsers = component$((props: { users: User[] }) => {
return (
<>
@@ -16,7 +20,7 @@ export const TaleUsers = component$((props: { users: User[] }) => {
)
})
export default component$((props: { users: any }) => {
export default component$((props: { users: User[] }) => {
return (
<section class="relative ">
<div class={'px-4 py-16 mx-auto max-w-6xl lg:py-20'}>

View File

@@ -0,0 +1,50 @@
/*
* WHAT IS THIS FILE?
*
* It's the entry point for the express server when building for production.
*
* Learn more about the cloudflare integration here:
* - https://qwik.builder.io/qwikcity/adaptors/node/
*
*/
import { createQwikCity } from '@builder.io/qwik-city/middleware/node'
import qwikCityPlan from '@qwik-city-plan'
import render from './entry.ssr'
import express from 'express'
import { fileURLToPath } from 'node:url'
import { join } from 'node:path'
import compression from 'compression'
// Directories where the static assets are located
const distDir = join(fileURLToPath(import.meta.url), '..', '..', 'dist')
const buildDir = join(distDir, 'build')
// Allow for dynamic port
const PORT = process.env.PORT ?? 3000
// Create the Qwik City express middleware
const { router, notFound } = createQwikCity({ render, qwikCityPlan })
// Create the express server
// https://expressjs.com/
const app = express()
// Enable gzip compression
app.use(compression())
// Static asset handlers
// https://expressjs.com/en/starter/static-files.html
app.use(`/build`, express.static(buildDir, { immutable: true, maxAge: '1y' }))
app.use(express.static(distDir, { redirect: false }))
// Use Qwik City's page and endpoint request handler
app.use(router)
// Use Qwik City's 404 handler
app.use(notFound)
// Start the express server
app.listen(PORT, () => {
/* eslint-disable */
console.log(`Server starter: http://localhost:${PORT}/`)
})

View File

@@ -0,0 +1,14 @@
/*
* WHAT IS THIS FILE?
*
* It's the entry point for netlify-edge when building for production.
*
* Learn more about the cloudflare integration here:
* - https://qwik.builder.io/qwikcity/adaptors/netlify-edge/
*
*/
import { createQwikCity } from '@builder.io/qwik-city/middleware/netlify-edge'
import qwikCityPlan from '@qwik-city-plan'
import render from './entry.ssr'
export default createQwikCity({ render, qwikCityPlan })

View File

@@ -1,54 +1,35 @@
import { component$, Resource } from '@builder.io/qwik'
import { DocumentHead, useEndpoint } from '@builder.io/qwik-city'
import Hero from '~/components/widgets/Hero'
import Features from '~/components/widgets/Features'
import FAQs from '~/components/widgets/FAQs'
// import Stats from '~/components/widgets/Stats'
import CallToAction from '~/components/widgets/CallToAction'
import Collaborators from '~/components/widgets/Collaborators'
import { fetchGithub } from '~/services/github'
import { RequestHandlerNetlify } from '@builder.io/qwik-city/middleware/netlify-edge'
import { GITHUB_TOKEN } from './docs/constant'
import { RequestHandlerCloudflarePages } from '@builder.io/qwik-city/middleware/cloudflare-pages'
export const apiGetCollaborators = async (token: string) => {
const data = await fetch(
`https://api.github.com/repos/codigoencasa/bot-whatsapp/contributors`,
{
method: 'GET',
headers: {
Accept: 'application/vnd.github+json',
'X-GitHub-Api-Version': '2022-11-28',
Authorization: `Bearer ${token}`,
},
}
)
const listUsers = data.json()
return listUsers
}
export const onRequest: RequestHandlerCloudflarePages = async ({
platform,
}) => {
export const onGet: RequestHandlerNetlify = async ({ platform }) => {
console.log(`[🚩 platform]: `, platform)
console.log(`[🚩 platform .env]: `, (platform as any)?.GITHUB_TOKEN)
const CHECK_GITHUB_TOKEN =
(platform as any)?.['GITHUB_TOKEN'] ?? GITHUB_TOKEN
return apiGetCollaborators(CHECK_GITHUB_TOKEN)
const data = await fetchGithub(CHECK_GITHUB_TOKEN)
return data
}
export default component$(() => {
const dataUser = useEndpoint()
const resource = useEndpoint()
return (
<>
<Hero />
<Features />
<CallToAction />
<Resource
value={dataUser}
onResolved={(users) => <Collaborators users={users} />}
value={resource}
onResolved={(data: any) => <Collaborators users={data} />}
></Resource>
<FAQs />
{/* <Stats /> */}
</>
)
})

View File

@@ -0,0 +1,19 @@
/**
* GET API from Github
* @returns
*/
export const fetchGithub = async (token: string) => {
const data = await fetch(
`https://api.github.com/repos/codigoencasa/bot-whatsapp/contributors`,
{
method: 'GET',
headers: {
Accept: 'application/vnd.github+json',
'X-GitHub-Api-Version': '2022-11-28',
Authorization: `Bearer ${token}`,
},
}
)
const listUsers = data.json()
return listUsers
}