Skip to content

Commit ebcd376

Browse files
committed
build(serverless): add aws lambda deploy facility
1 parent a92e50b commit ebcd376

17 files changed

+4375
-472
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,10 @@ testem.log
4040
# System Files
4141
.DS_Store
4242
Thumbs.db
43+
44+
# Serverless
45+
46+
admin.env
47+
.env
48+
_meta
49+
.serverless

angular.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"tsConfig": "src/tsconfig.app.json",
1818
"polyfills": "src/polyfills.ts",
1919
"assets": [
20-
"src/assets",
20+
"src/assets"
2121
],
2222
"styles": [
2323
"src/theme/styles.scss"
@@ -84,7 +84,7 @@
8484
},
8585
"defaultProject": "material-angular-dashboard",
8686
"cli": {
87-
"packageManager": "yarn"
87+
"packageManager": "npm"
8888
},
8989
"schematics": {
9090
"@schematics/angular:component": {

backend/index.js

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,4 @@
1-
import express from 'express';
2-
import * as bodyParser from 'body-parser';
3-
import cookieParser from 'cookie-parser';
4-
import passport from 'passport';
5-
import cors from 'cors';
6-
import { Strategy as LocalStrategy } from 'passport-local';
7-
import { Strategy as JwtStrategy, ExtractJwt } from 'passport-jwt';
8-
9-
import rootRouter from './routes';
10-
11-
const app = express();
12-
13-
app.use(cors());
14-
app.use(cookieParser());
15-
app.use(bodyParser.json());
16-
app.use(bodyParser.urlencoded({ extended: true }));
17-
app.use(passport.initialize());
18-
19-
const mockUser = {
20-
id: 0,
21-
22-
username: 'admin',
23-
password: 'admin',
24-
};
25-
26-
passport.use(new LocalStrategy(
27-
{
28-
usernameField: 'email',
29-
passwordField: 'password',
30-
},
31-
(email, password, done) => {
32-
// Here you can insert your own logic.
33-
// See examples here: http://www.passportjs.org/docs/downloads/html/#configure
34-
if (email !== mockUser.email) {
35-
return done(null, false, { message: 'Incorrect email.' });
36-
}
37-
if (password !== mockUser.password) {
38-
return done(null, false, { message: 'Incorrect password.' });
39-
}
40-
return done(null, mockUser);
41-
},
42-
));
43-
44-
passport.use(new JwtStrategy(
45-
{
46-
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
47-
secretOrKey: 'secret',
48-
},
49-
(payload, done) => {
50-
// Here you can insert your own logic.
51-
if (payload.id !== mockUser.id) {
52-
return done(null, false, { message: 'Incorrect username.' });
53-
}
54-
return done(null, mockUser);
55-
},
56-
));
57-
58-
app.use(rootRouter);
1+
import { app } from "./server";
592

603
const port = 3000;
614

backend/lambda.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// generated by @ng-toolkit/serverless
2+
const awsServerlessExpress = require('aws-serverless-express');
3+
const server = require('./dist/server');
4+
const awsServerlessExpressMiddleware = require('aws-serverless-express/middleware');
5+
6+
const binaryMimeTypes = [
7+
'application/javascript',
8+
'application/json',
9+
'application/octet-stream',
10+
'application/xml',
11+
'image/jpeg',
12+
'image/png',
13+
'image/gif',
14+
'text/comma-separated-values',
15+
'text/css',
16+
'text/html',
17+
'text/javascript',
18+
'text/plain',
19+
'text/text',
20+
'text/xml',
21+
'image/x-icon',
22+
'image/svg+xml',
23+
'application/x-font-ttf'
24+
];
25+
26+
server.app.use(awsServerlessExpressMiddleware.eventContext());
27+
28+
const serverProxy = awsServerlessExpress.createServer(server.app, null, binaryMimeTypes);
29+
module.exports.universal = (event, context) => awsServerlessExpress.proxy(serverProxy, event, context);

0 commit comments

Comments
 (0)