forked from QwikDev/qwik
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(adapter): aws starter adapter (QwikDev#4390)
- Loading branch information
1 parent
685cf3d
commit e78368f
Showing
5 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
starters/adapters/aws-lambda/adapters/aws-lambda/vite.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { nodeServerAdapter } from '@builder.io/qwik-city/adapters/node-server/vite'; | ||
import { extendConfig } from '@builder.io/qwik-city/vite'; | ||
import baseConfig from '../../vite.config'; | ||
|
||
export default extendConfig(baseConfig, () => { | ||
return { | ||
build: { | ||
ssr: true, | ||
rollupOptions: { | ||
input: ['src/entry_aws-lambda.tsx', 'src/entry.ssr.tsx', '@qwik-city-plan'], | ||
}, | ||
}, | ||
plugins: [nodeServerAdapter({ name: 'express' })], | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"description": "AWS Lambda", | ||
"scripts": { | ||
"build.server": "vite build -c adapters/aws-lambda/vite.config.ts", | ||
"serverless:preview": "qwik build && serverless offline" | ||
}, | ||
"devDependencies": { | ||
"express": "4.18.2", | ||
"@types/express": "4.17.17", | ||
"@vendia/serverless-express": "^4.10.4", | ||
"source-map-support": "^0.5.21", | ||
"serverless": "^3.32.2", | ||
"serverless-offline": "^12.0.4", | ||
"serverless-plugin-common-excludes": "^4.0.0", | ||
"serverless-plugin-include-dependencies": "^5.1.0" | ||
}, | ||
"__qwik__": { | ||
"priority": 30, | ||
"displayName": "Adapter: AWS Lambda", | ||
"docs": [ | ||
"https://qwik.builder.io/qwikcity/adaptors/aws-lambda/", | ||
"https://aws.amazon.com/es/lambda/", | ||
"https://www.serverless.com/cloud/docs/get-started" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
service: qwik-lambda-app | ||
frameworkVersion: '3' | ||
|
||
provider: | ||
name: aws | ||
runtime: nodejs18.x | ||
region: us-west-1 | ||
memorySize: 128 | ||
timeout: 10 | ||
stage: dev | ||
|
||
functions: | ||
qwik: | ||
handler: server/entry_aws-lambda.qwikApp | ||
events: | ||
- httpApi: '*' | ||
|
||
custom: | ||
serverless-offline: | ||
httpPort: 4000 | ||
|
||
package: | ||
excludeDevDependencies: false | ||
|
||
plugins: | ||
- serverless-offline | ||
- serverless-plugin-common-excludes | ||
- serverless-plugin-include-dependencies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* WHAT IS THIS FILE? | ||
* | ||
* It's the entry point for the Express HTTP server when building for production. | ||
* | ||
* Learn more about Node.js server integrations here: | ||
* - https://qwik.builder.io/docs/deployments/node/ | ||
* | ||
*/ | ||
import 'source-map-support/register'; | ||
import { createQwikCity, type PlatformNode } from '@builder.io/qwik-city/middleware/node'; | ||
import qwikCityPlan from '@qwik-city-plan'; | ||
import { manifest } from '@qwik-client-manifest'; | ||
import serverlessExpress from '@vendia/serverless-express'; | ||
import render from './entry.ssr'; | ||
import express from 'express'; | ||
import { fileURLToPath } from 'node:url'; | ||
import { join } from 'node:path'; | ||
|
||
declare global { | ||
interface QwikCityPlatform extends PlatformNode {} | ||
} | ||
|
||
// import compression from 'compression'; | ||
|
||
// Directories where the static assets are located | ||
const distDir = join(fileURLToPath(import.meta.url), '..', '..', 'dist'); | ||
const buildDir = join(distDir, 'build'); | ||
|
||
// Create the Qwik City Node middleware | ||
const { router, notFound } = createQwikCity({ render, qwikCityPlan, manifest }); | ||
|
||
// 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); | ||
|
||
export const qwikApp = serverlessExpress({ app }); |