forked from activescott/serverless-aws-static-file-handler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.js
More file actions
29 lines (25 loc) · 1.02 KB
/
handler.js
File metadata and controls
29 lines (25 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"use strict"
const path = require("path")
const StaticFileHandler = require("serverless-aws-static-file-handler")
const clientFilesPath = path.join(__dirname, "./data-files/")
const fileHandler = new StaticFileHandler(clientFilesPath)
module.exports.root = async (event, context) => {
event.path = "index.html" // forcing a specific page for this handler; ignore requested path
return fileHandler.get(event, context)
}
module.exports.v2_root = async (event, context) => {
event.rawPath = "index.html" // forcing a specific page for this handler; ignore requested path
return fileHandler.get(event, context)
}
module.exports.binary = async (event, context) => {
if (!event.path.startsWith("/binary/")) {
throw new Error(`[404] Invalid filepath for this resource`)
}
return fileHandler.get(event, context)
}
module.exports.v2_binary = async (event, context) => {
if (!event.rawPath.startsWith("/v2/binary/")) {
throw new Error(`[404] Invalid filepath for this resource`)
}
return fileHandler.get(event, context)
}