Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(adapter): aws starter adapter #4390

Merged
merged 14 commits into from
Jun 11, 2023
Merged
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions starters/adapters/aws-lambda/adapters/aws-lambda/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { nodeServerAdapter } from '@builder.io/qwik-city/adapters/node-server/vite';
import { extendConfig } from '@builder.io/qwik-city/vite';
import baseConfig from '../../vite.config';
import { writeFileSync } from 'node:fs';
import { join } from 'node:path';

export const entryPointWithDot = () => ({
leifermendez marked this conversation as resolved.
Show resolved Hide resolved
name: 'rename-entry-point',
writeBundle() {
const output = join(process.cwd(), 'server', 'aws.js');
writeFileSync(output, 'export * from "./entry.aws-lambda.mjs";');
},
});

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' }), entryPointWithDot()],
};
});
26 changes: 26 additions & 0 deletions starters/adapters/aws-lambda/package.json
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": "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"
]
}
}
24 changes: 24 additions & 0 deletions starters/adapters/aws-lambda/serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
service: aws
frameworkVersion: '3'

provider:
name: aws
runtime: nodejs18.x

functions:
hello:
handler: server/aws.qwikApp
events:
- httpApi: '*'

custom:
serverless-offline:
httpPort: 4000

package:
excludeDevDependencies: false

plugins:
- serverless-offline
- serverless-plugin-common-excludes
- serverless-plugin-include-dependencies
51 changes: 51 additions & 0 deletions starters/adapters/aws-lambda/src/entry.aws-lambda.tsx
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 });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image