hammady / wwpray

A website that shows the prayer times for a preconfigured list of masjids in a tabular format. Visitors can subscribe for email notifications.
https://wwpray.net
MIT License
1 stars 0 forks source link

Use JS API to generate static site #20

Closed hammady closed 1 year ago

hammady commented 1 year ago

AWS Lambda has limitations running npm commands, or probably commands in general (see below for the error when invoked on aws, it works perfectly fine locally). The original plan was to build the static site using a node function (JS API), not a shell command. The current implementation is a hack where it invokes a shell command from a node function. There are 2 pieces in this puzzle:

  1. Installing the dev dependencies automatically. This can be done by merging the 2 package.json files, the root one in the generator service and the one in the svelte directory. I hope there was a cleaner method in node, but we may need to get around by doing this.
  2. Invoking the build using JS API. I found this: https://v2.vitejs.dev/guide/api-javascript.html#build. It seems possible with some configuration I guess to accommodate for svelte static generation.

Error logs:

10:26:44:353 PM - Oct 12 2023
AWS LAMBDA
dev
wwpray
generator
generator-dev-generator
npm ERR! code ENOENT
10:26:44:353 PM - Oct 12 2023
AWS LAMBDA
dev
wwpray
generator
generator-dev-generator
npm ERR! syscall mkdir
10:26:44:354 PM - Oct 12 2023
AWS LAMBDA
dev
wwpray
generator
generator-dev-generator
npm ERR! path /home/sbx_user1051
10:26:44:354 PM - Oct 12 2023
AWS LAMBDA
dev
wwpray
generator
generator-dev-generator
npm ERR! errno -2
10:26:44:370 PM - Oct 12 2023
AWS LAMBDA
dev
wwpray
generator
generator-dev-generator
npm ERR! enoent ENOENT: no such file or directory, mkdir '/home/sbx_user1051'
10:26:44:370 PM - Oct 12 2023
AWS LAMBDA
dev
wwpray
generator
generator-dev-generator
npm ERR! enoent This is related to npm not being able to find a file.
10:26:44:370 PM - Oct 12 2023
AWS LAMBDA
dev
wwpray
generator
generator-dev-generator
npm ERR! enoent 
10:26:44:372 PM - Oct 12 2023
AWS LAMBDA
dev
wwpray
generator
generator-dev-generator
npm ERR! Log files were not written due to an error writing to the directory: /home/sbx_user1051/.npm/_logs

FYI, the file-system for lambda is read-only. The only writable location is /tmp. I am not sure what led to the creation of the above folder. It could be easily fixable from the npm command.

hammady commented 1 year ago

For the first point, we need to include dev dependencies when packaging the service. We are literally running dev commands from the deployed function.

hammady commented 1 year ago

@fayez-nazzal generation works perfectly on AWS! Many thanks for all your work so far!