-
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.
chore: set webpack and lambda setting
- Loading branch information
Showing
9 changed files
with
7,034 additions
and
3,957 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,37 @@ | ||
service: dorabangs-node | ||
plugins: | ||
- serverless-dotenv-plugin | ||
- serverless-offline | ||
|
||
provider: | ||
name: aws | ||
runtime: nodejs20.x | ||
region: ap-northeast-2 | ||
architecture: arm64 | ||
|
||
custom: | ||
dotenv: | ||
basePath: ./ | ||
optimize: | ||
external: ['swagger-ui-dist'] | ||
|
||
functions: | ||
server: | ||
handler: dist/index.handler | ||
events: | ||
- http: | ||
method: any | ||
path: '/' | ||
cors: | ||
origin: '*' | ||
- http: | ||
method: any | ||
path: '{proxy+}' | ||
cors: | ||
origin: '*' | ||
|
||
package: | ||
exclude: | ||
- '**/*' | ||
include: | ||
- 'dist/**' |
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
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
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 @@ | ||
import { NestFactory } from '@nestjs/core'; | ||
import { ExpressAdapter } from '@nestjs/platform-express'; | ||
import express from 'express'; | ||
import { AppModule } from './app.module'; | ||
import { nestSwaggerConfig } from './app.swagger'; | ||
import { nestAppConfig } from './app.config'; | ||
|
||
export async function bootstrap() { | ||
const expressInstance: express.Express = express(); | ||
const app = await NestFactory.create( | ||
AppModule, | ||
new ExpressAdapter(expressInstance), | ||
{ cors: true }, | ||
); | ||
|
||
// Config Nest.js Application | ||
nestAppConfig(app); | ||
// Config application Swagger | ||
nestSwaggerConfig(app); | ||
|
||
return { app, expressInstance }; | ||
} | ||
|
||
export async function runServer() { | ||
const { app } = await bootstrap(); | ||
await app.listen(3000); | ||
return app; | ||
} |
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 @@ | ||
import { Context, Handler } from 'aws-lambda'; | ||
import { createServer, proxy } from 'aws-serverless-express'; | ||
import { Server } from 'http'; | ||
import { bootstrap, runServer } from './bootstrap'; | ||
let cachedServer: Server; | ||
export const handler: Handler = async (event: any, context: Context) => { | ||
if (!cachedServer) { | ||
const { app, expressInstance } = await bootstrap(); | ||
await app.init(); | ||
cachedServer = createServer(expressInstance); | ||
} | ||
|
||
if (event.path === '/docs') { | ||
event.path = '/docs/'; | ||
} | ||
if (event.path) { | ||
event.path = event.path.includes('swagger-ui') | ||
? `/docs${event.path}` | ||
: event.path; | ||
} | ||
return proxy(cachedServer, event, context, 'PROMISE').promise; | ||
}; | ||
|
||
if (process.env.NODE_ENV === 'local') { | ||
runServer() | ||
.then(() => console.log('Nest Ready')) | ||
.catch((error) => console.log(error)); | ||
} |
This file was deleted.
Oops, something went wrong.
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
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,97 @@ | ||
import CopyPlugin from 'copy-webpack-plugin'; | ||
import * as path from 'path'; | ||
import * as webpack from 'webpack'; | ||
const swaggerUiModulePath = path.dirname(require.resolve('swagger-ui-dist')); | ||
module.exports = { | ||
entry: './src/handler.ts', | ||
mode: 'none', | ||
target: 'node', | ||
devtool: 'source-map', | ||
plugins: [ | ||
new webpack.IgnorePlugin({ | ||
checkResource(resource) { | ||
const lazyImports = [ | ||
'./swagger-ui-bundle.js', | ||
'./swagger-ui-standalone-preset.js', | ||
'class-validator', | ||
'class-transformer/storage', | ||
'@nestjs/swagger', | ||
'fastify-swagger', | ||
'@nestjs/microservices', | ||
'@nestjs/platform-fastify', | ||
'@nestjs/websockets/socket-module', | ||
'@nestjs/microservices/microservices-module', | ||
// mongodb optionals | ||
'mongodb-client-encryption', | ||
'bson-ext', | ||
'kerberos', | ||
'aws4', | ||
'snappy', | ||
'gcp-metadata', | ||
'@mongodb-js/zstd', | ||
'snappy/package.json', | ||
]; | ||
if (!lazyImports.includes(resource)) { | ||
return false; | ||
} | ||
try { | ||
require.resolve(resource); | ||
} catch (err) { | ||
return true; | ||
} | ||
return false; | ||
}, | ||
}), | ||
new CopyPlugin({ | ||
patterns: [ | ||
{ | ||
from: `${swaggerUiModulePath}/swagger-ui.css`, | ||
to: 'swagger-ui.css', | ||
}, | ||
{ | ||
from: `${swaggerUiModulePath}/swagger-ui-bundle.js`, | ||
to: 'swagger-ui-bundle.js', | ||
}, | ||
{ | ||
from: `${swaggerUiModulePath}/swagger-ui-standalone-preset.js`, | ||
to: 'swagger-ui-standalone-preset.js', | ||
}, | ||
{ | ||
from: `${swaggerUiModulePath}/favicon-32x32.png`, | ||
to: 'favicon-32x32.png', | ||
}, | ||
{ | ||
from: `${swaggerUiModulePath}/favicon-16x16.png`, | ||
to: 'favicon-16x16.png', | ||
}, | ||
{ | ||
from: `${swaggerUiModulePath}/oauth2-redirect.html`, | ||
to: 'src/oauth2-redirect.html', | ||
}, | ||
], | ||
}), | ||
], | ||
externals: {}, | ||
resolve: { | ||
extensions: ['.ts', '.js'], | ||
alias: { | ||
'@src': path.resolve(__dirname, 'src'), | ||
}, | ||
}, | ||
output: { | ||
path: path.resolve(__dirname, 'dist'), | ||
filename: 'index.js', | ||
libraryTarget: 'commonjs', | ||
}, | ||
module: { | ||
rules: [{ test: /\.ts$/, loader: 'ts-loader' }], | ||
}, | ||
stats: { | ||
warningsFilter: [ | ||
'optional-require', | ||
'load-package.util', | ||
'load-adapter', | ||
() => false, | ||
], | ||
}, | ||
}; |