From 6eef36631ffc383ed59d20d3b0de63c244262eab Mon Sep 17 00:00:00 2001 From: jimmytai Date: Thu, 14 Mar 2024 11:33:53 +0800 Subject: [PATCH] 20240314 --- cors.js => api/cors.js | 0 api/notFound.js | 5 +++++ index.js | 3 ++- line/handler/index.js | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) rename cors.js => api/cors.js (100%) create mode 100644 api/notFound.js diff --git a/cors.js b/api/cors.js similarity index 100% rename from cors.js rename to api/cors.js diff --git a/api/notFound.js b/api/notFound.js new file mode 100644 index 0000000..84bdd0e --- /dev/null +++ b/api/notFound.js @@ -0,0 +1,5 @@ +const createError = require('http-errors') + +module.exports = async (ctx, next) => { + throw createError(404) +} diff --git a/index.js b/index.js index 58ae477..211330f 100644 --- a/index.js +++ b/index.js @@ -6,9 +6,10 @@ const { middlewareCompose } = require('./libs/helper') const functions = require('@google-cloud/functions-framework') const handlers = middlewareCompose([ - require('./cors'), + require('./api/cors'), require('./api/index'), require('./line/handler/index'), + require('./api/notFound'), ]) functions.http('main', async (req, res) => { diff --git a/line/handler/index.js b/line/handler/index.js index 42fd504..817f2d4 100644 --- a/line/handler/index.js +++ b/line/handler/index.js @@ -13,6 +13,7 @@ const lineEventHander = middlewareCompose([ module.exports = async (ctx, next) => { const { req, res } = ctx + if (req.method !== 'POST' || _.isNil(req.get('x-line-signature'))) return await next() try { // 處理 access token const channelAccessToken = req.path.substring(1)