mirror of
https://github.com/uetchy/namae.git
synced 2025-03-17 12:30:32 +09:00
feat: improve cache
This commit is contained in:
parent
6c84493360
commit
85520b2417
@ -1,4 +1,4 @@
|
|||||||
import nodeFetch from 'isomorphic-unfetch'
|
import nodeFetch from 'isomorphic-unfetch';
|
||||||
|
|
||||||
export type HttpMethod =
|
export type HttpMethod =
|
||||||
| 'GET'
|
| 'GET'
|
||||||
@ -8,28 +8,28 @@ export type HttpMethod =
|
|||||||
| 'HEAD'
|
| 'HEAD'
|
||||||
| 'PATCH'
|
| 'PATCH'
|
||||||
| 'CONNECT'
|
| 'CONNECT'
|
||||||
| 'TRACE'
|
| 'TRACE';
|
||||||
|
|
||||||
export interface NowRequest<T = {query: string}> {
|
export interface NowRequest<T = {query: string}> {
|
||||||
query: T
|
query: T;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NowResponse {
|
export interface NowResponse {
|
||||||
setHeader: (label: string, body: string) => void
|
setHeader: (label: string, body: string) => void;
|
||||||
json: (obj: object) => void
|
json: (obj: object) => void;
|
||||||
status: (code: number) => NowResponse
|
status: (code: number) => NowResponse;
|
||||||
length: number
|
length: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fetch(url: string, method: HttpMethod = 'HEAD') {
|
export function fetch(url: string, method: HttpMethod = 'HEAD') {
|
||||||
return nodeFetch(url, { method: method })
|
return nodeFetch(url, {method: method});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function send(res: NowResponse, data: object) {
|
export function send(res: NowResponse, data: object) {
|
||||||
res.setHeader('Cache-Control', 'maxage=0, s-maxage=43200')
|
res.setHeader('Cache-Control', 's-maxage=86400');
|
||||||
res.json(data)
|
res.json(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sendError(res: NowResponse, error: Error) {
|
export function sendError(res: NowResponse, error: Error) {
|
||||||
res.status(400).json({ error: error.message })
|
res.status(400).json({error: error.message});
|
||||||
}
|
}
|
||||||
|
5
now.json
5
now.json
@ -10,7 +10,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"src": "/api/services/*.ts",
|
"src": "/api/services/*.ts",
|
||||||
"use": "@now/node@canary"
|
"use": "@now/node"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"routes": [
|
"routes": [
|
||||||
@ -20,7 +20,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"src": "/(.*)",
|
"src": "/(.*)",
|
||||||
"dest": "/web/$1"
|
"dest": "/web/$1",
|
||||||
|
"headers": {"cache-control": "s-maxage=86400"}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"env": {
|
"env": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user