-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lambda-tiler): remove
@basemaps/lambda
and replace with `@linz…
…js/lambda` (#1821) * feat(lambda-tiler): remote `@basemaps/lambda` and replace with `@linzjs/lambda` * refactor: remove unused reference * refactor: use undefined to prevent a ! assertion Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
9367e3f
commit cb22b3d
Showing
41 changed files
with
183 additions
and
1,194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Const } from '@basemaps/shared'; | ||
import { HttpHeader, LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda'; | ||
|
||
export type ReqCallback = (req: LambdaHttpRequest) => Promise<LambdaHttpResponse>; | ||
|
||
export interface ActionData { | ||
version: string; | ||
name: string; | ||
rest: string[]; | ||
} | ||
|
||
export class Router { | ||
static action(req: LambdaHttpRequest): ActionData { | ||
const path = req.path; | ||
const [version, name, ...rest] = (path[0] === '/' ? path.slice(1) : path).split('/'); | ||
if (name == null) return { version: 'v1', name: version, rest: [] }; | ||
return { version, name, rest }; | ||
} | ||
|
||
static apiKey(req: LambdaHttpRequest): string | undefined { | ||
const apiKey = req.query.get(Const.ApiKey.QueryString) ?? req.header('X-LINZ-Api-Key'); | ||
if (apiKey != null && !Array.isArray(apiKey)) { | ||
req.set(Const.ApiKey.QueryString, this.apiKey); | ||
return apiKey; | ||
} | ||
return; | ||
} | ||
|
||
private handlers: Record<string, ReqCallback> = {}; | ||
|
||
async handle(req: LambdaHttpRequest): Promise<LambdaHttpResponse> { | ||
// Allow cross origin requests | ||
if (req.method === 'options') { | ||
return new LambdaHttpResponse(200, 'Options', { | ||
[HttpHeader.Cors]: '*', | ||
'Access-Control-Allow-Credentials': 'false', | ||
'Access-Control-Allow-Methods': 'OPTIONS,GET,PUT,POST,DELETE', | ||
}); | ||
} | ||
|
||
if (req.method !== 'GET') return new LambdaHttpResponse(405, 'Method not allowed'); | ||
|
||
const action = Router.action(req); | ||
const handler = action.version === 'v1' ? this.handlers[action.name] : null; | ||
if (handler == null) return new LambdaHttpResponse(404, 'Not Found'); | ||
|
||
const response = await handler(req); | ||
response.header(HttpHeader.Cors, '*'); | ||
return response; | ||
} | ||
|
||
get(path: string, handler: ReqCallback): void { | ||
if (this.handlers[path] != null) throw new Error(path + ' already registered'); | ||
this.handlers[path] = handler; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.