Skip to content

Commit fac5867

Browse files
author
Fuss Florian (uid10804)
committed
refactor(template): use local filesystem when sls offline is used - no AWS credentials needed
1 parent f1b488a commit fac5867

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ There are components managed: (under /packages)
214214
make install
215215
```
216216
217+
Lerna will be used to manage the monorepo`s dependencies.
218+
219+
```
220+
lerna bootstrap
221+
```
222+
217223
### Start the server component
218224
219225
```bash
@@ -224,13 +230,13 @@ the json file will be loaded directly from your local filesystem. No AWS access
224230

225231
### Start the template component
226232

227-
Mind: Ensure you have AWS credentials in place due to requests to S3 bucket.
233+
This part is using the serverless offline and is close to how the solution behaves in the cloud.
228234

229235
```bash
230236
make start-template
231237
```
232238

233-
the json file will be loaded directly from the s3 bucket. This is very close to how the solution behaves in the lambda and aws cloud.
239+
the json file will be loaded directly from your local filesystem. No AWS access is needed.
234240

235241
### Start the cli component
236242

packages/template/src/handler.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
S3StorageAdapter,
99
CloudEnvironment,
1010
CoreApp,
11+
FileStorageAdapter,
1112
} from 'json-serverless-lib';
1213

1314
import fs from 'fs';
@@ -25,17 +26,28 @@ const swagger = new Swagger(
2526
'./package.json'
2627
);
2728

28-
const core = new CoreApp(
29-
appConfig,
30-
server,
31-
new S3StorageAdapter(environment.s3Bucket, environment.s3File),
32-
swagger,
33-
environment
34-
);
29+
let core: CoreApp | undefined;
30+
if (process.env.IS_OFFLINE) {
31+
core = new CoreApp(
32+
appConfig,
33+
server,
34+
new FileStorageAdapter('db.json'),
35+
swagger,
36+
environment
37+
);
38+
} else {
39+
core = new CoreApp(
40+
appConfig,
41+
server,
42+
new S3StorageAdapter(environment.s3Bucket, environment.s3File),
43+
swagger,
44+
environment
45+
);
46+
}
3547

3648
const init = async () => {
3749
return new Promise(async (resolve, reject) => {
38-
await core.setup();
50+
await core!.setup();
3951
resolve();
4052
});
4153
};

0 commit comments

Comments
 (0)