FirebaseでLINE Botをつくっています。
「firebase serve --only functions, hosting」 を実行し、「http://localhost:5000/webhook」を開いたのですが、
Cannot GET /xxx/us-central1/app/webhook
と表示されてしまいます。
コードは下記です。
index.ts
JavaScript
1'use strict'; 2 3const functions = require('firebase-functions'); 4const express = require('express'); 5const line = require('@line/bot-sdk'); 6 7const config = { 8 channelSecret: 'channelSecret', 9 channelAccessToken: 'channelAccessToken' 10}; 11 12const app = express(); 13 14app.post('/webhook', line.middleware(config), (req: any, res: any) => { 15 console.log(req.body.events); 16 Promise 17 .all(req.body.events.map(handleEvent)) 18 .then((result) => res.json(result)) 19 .catch((result) => console.log('error!!!')); 20}); 21 22const client = new line.Client(config); 23 24async function handleEvent(event: any) { 25 if (event.type !== 'message' || event.message.type !== 'text') { 26 return Promise.resolve(null); 27 } 28 29 return client.replyMessage(event.replyToken, { 30 type: 'text', 31 text: event.message.text 32 }); 33} 34 35exports.app = functions.https.onRequest(app);
firebase.json
{ "hosting": { "public": "./", "rewrites": [{ "source": "/webhook", "function": "app" }], "ignore": [ "firebase.json", "**/.*", "**/node_modules/**" ] } }
package.json
{ "name": "functions", "scripts": { "lint": "tslint --project tsconfig.json", "build": "tsc", "serve": "npm run build && firebase serve --only functions --project golfure", "shell": "npm run build && firebase functions:shell", "start": "npm run shell", "deploy": "firebase deploy --only functions", "logs": "firebase functions:log" }, "engines": { "node": "8" }, "main": "lib/index.js", "dependencies": { "@line/bot-sdk": "^6.8.2", "express": "^4.17.1", "firebase-admin": "^8.6.0", "firebase-functions": "^3.3.0", "ngrok": "^3.2.5" }, "devDependencies": { "tslint": "^5.12.0", "typescript": "^3.2.2", "firebase-functions-test": "^0.1.6" }, "private": true }
よろしくお願いいたします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。