Check in
This commit is contained in:
commit
dedce8e438
7 changed files with 3573 additions and 0 deletions
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
# package directories
|
||||
node_modules
|
||||
jspm_packages
|
||||
|
||||
# Serverless directories
|
||||
.serverless
|
||||
|
||||
# Webpack directories
|
||||
.webpack
|
28
handler.ts
Normal file
28
handler.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
import { APIGatewayProxyHandler } from "aws-lambda";
|
||||
import axios from "axios";
|
||||
import "source-map-support/register";
|
||||
import { JSDOM } from "jsdom";
|
||||
|
||||
export const promiseList: APIGatewayProxyHandler = async (_, _context) => {
|
||||
const page = await axios({
|
||||
url: "https://tracciailgoverno.pagellapolitica.it/it/promesse/",
|
||||
responseType: "document"
|
||||
});
|
||||
const { window } = new JSDOM(page.data);
|
||||
const promises = window.document.querySelectorAll(".promise");
|
||||
const promiseList = Array.prototype.slice.call(promises, 0);
|
||||
return {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify(
|
||||
promiseList.map(
|
||||
prom => ({
|
||||
name: prom.querySelector("h2.heading span").innerHTML,
|
||||
url: prom.querySelector("a[href]").href,
|
||||
status: prom.querySelector(".promise-status-text").innerHTML
|
||||
}),
|
||||
null,
|
||||
2
|
||||
)
|
||||
)
|
||||
};
|
||||
};
|
25
package.json
Normal file
25
package.json
Normal file
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"name": "promessegoverno",
|
||||
"version": "1.0.0",
|
||||
"description": "Serverless webpack example using Typescript",
|
||||
"main": "handler.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.19.0",
|
||||
"jsdom": "^15.1.1",
|
||||
"source-map-support": "^0.5.10"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/aws-lambda": "^8.10.17",
|
||||
"@types/jsdom": "^12.2.4",
|
||||
"@types/node": "^10.12.18",
|
||||
"serverless-webpack": "^5.2.0",
|
||||
"ts-loader": "^5.3.3",
|
||||
"typescript": "^3.2.4",
|
||||
"webpack": "^4.29.0"
|
||||
},
|
||||
"author": "The serverless webpack authors (https://github.com/elastic-coders/serverless-webpack)",
|
||||
"license": "MIT"
|
||||
}
|
20
serverless.yml
Normal file
20
serverless.yml
Normal file
|
@ -0,0 +1,20 @@
|
|||
service:
|
||||
name: promessegoverno
|
||||
app: promessegoverno-app
|
||||
org: hamcha
|
||||
|
||||
# Add the serverless-webpack plugin
|
||||
plugins:
|
||||
- serverless-webpack
|
||||
|
||||
provider:
|
||||
name: aws
|
||||
runtime: nodejs10.x
|
||||
|
||||
functions:
|
||||
promiseList:
|
||||
handler: handler.promiseList
|
||||
events:
|
||||
- http:
|
||||
method: get
|
||||
path: promiseList
|
12
tsconfig.json
Normal file
12
tsconfig.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"lib": ["es2017"],
|
||||
"moduleResolution": "node",
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"sourceMap": true,
|
||||
"target": "es2017",
|
||||
"outDir": "lib"
|
||||
},
|
||||
"exclude": ["node_modules"]
|
||||
}
|
25
webpack.config.js
Normal file
25
webpack.config.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
const path = require("path");
|
||||
const slsw = require("serverless-webpack");
|
||||
const webpack = require("webpack");
|
||||
|
||||
module.exports = {
|
||||
mode: slsw.lib.webpack.isLocal ? "development" : "production",
|
||||
entry: slsw.lib.entries,
|
||||
devtool: "source-map",
|
||||
resolve: {
|
||||
extensions: [".js", ".jsx", ".json", ".ts", ".tsx"]
|
||||
},
|
||||
output: {
|
||||
libraryTarget: "commonjs",
|
||||
path: path.join(__dirname, ".webpack"),
|
||||
filename: "[name].js"
|
||||
},
|
||||
target: "node",
|
||||
module: {
|
||||
rules: [
|
||||
// all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
|
||||
{ test: /\.tsx?$/, loader: "ts-loader" }
|
||||
]
|
||||
},
|
||||
plugins: [new webpack.IgnorePlugin(/canvas$/)]
|
||||
};
|
Loading…
Reference in a new issue