現場情報・工期・規模・面積・金額・原価金額・添付ファイルを管理します
| 現場名 | 見積番号 | 工期 | 階 | 戸 | 受注決定 | 概算金額 | 提出見積 | 原価設定 | 添付 | 操作 |
|---|
業者マスタ — 許可証・協力会・インボイスを管理します
| 業者名 | 建設業許可証 | 協力会 | インボイス番号 | 操作 |
|---|
CREATE TABLE app_data(id TEXT PRIMARY KEY DEFAULT 'main',data JSONB,updated_at TIMESTAMPTZ DEFAULT NOW()); ALTER TABLE app_data ENABLE ROW LEVEL SECURITY; CREATE POLICY "allow_all" ON app_data FOR ALL USING(true) WITH CHECK(true);
export default {
async fetch(req) {
const cors = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type'
};
// CORS preflight
if (req.method === 'OPTIONS') {
return new Response(null, { headers: cors });
}
// GET: 動作確認用(ブラウザ直アクセスでも正常応答)
if (req.method === 'GET') {
return new Response(
JSON.stringify({ ok: true, running: true, message: 'LINE WORKS Proxy is running' }),
{ headers: { 'Content-Type': 'application/json', ...cors } }
);
}
// POST: JSONボディを解析
let body;
try {
body = await req.json();
} catch (e) {
return new Response(
JSON.stringify({ ok: false, error: 'JSON parse error: ' + e.message }),
{ status: 400, headers: { 'Content-Type': 'application/json', ...cors } }
);
}
const { webhookUrl, message } = body;
// 接続テスト用(__test__ または空)
if (!webhookUrl || webhookUrl === '__test__') {
return new Response(
JSON.stringify({ ok: true, status: 200, test: true }),
{ headers: { 'Content-Type': 'application/json', ...cors } }
);
}
// LINE WORKS に転送 ★ 正しいフォーマット: { content: { type, text } }
try {
const res = await fetch(webhookUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ body: { text: message } }) // ★ LINE WORKS 正しいフォーマット
});
return new Response(
JSON.stringify({ ok: res.ok, status: res.status }),
{ headers: { 'Content-Type': 'application/json', ...cors } }
);
} catch (e) {
return new Response(
JSON.stringify({ ok: false, error: e.message }),
{ status: 500, headers: { 'Content-Type': 'application/json', ...cors } }
);
}
}
};