-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #306 from cioos-siooc/267-add-url-test-to-resources
267 add url test to resources
- Loading branch information
Showing
10 changed files
with
261 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const functions = require("firebase-functions"); | ||
const fetch = require('node-fetch'); | ||
|
||
// Function to check if a given URL is active | ||
exports.checkURLActive = functions.https.onCall(async (data) => { | ||
let url = data; | ||
functions.logger.log('Received URL:', url); | ||
|
||
if (!url) { | ||
throw new functions.https.HttpsError('invalid-argument', 'The function must be called with one argument "url".'); | ||
} | ||
|
||
// Prepend 'http://' if the URL does not start with 'http://' or 'https://' | ||
if (!url.startsWith('http://') && !url.startsWith('https://')) { | ||
url = 'http://' + url; | ||
} | ||
|
||
try { | ||
const response = await fetch(url, {method: "HEAD" }); | ||
functions.logger.log(`Fetch response status for ${url}:`, response.status); | ||
return response.ok; // Return true if response is OK, otherwise false | ||
} catch (error) { | ||
functions.logger.error('Error in checkURLActive for URL:', url, error); | ||
return false; // Return false if an error occurs | ||
} | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.