diff --git a/.eslintrc.json b/.eslintrc.json index d25f5f4..06ca749 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -25,7 +25,7 @@ ], "quotes": [ "error", - "double" + "single" ] } } diff --git a/api/index.js b/api/index.js index 6892a9c..9a9a055 100644 --- a/api/index.js +++ b/api/index.js @@ -1,25 +1,21 @@ -import fetch from "node-fetch" +import fetch from 'node-fetch' -import connectToDatabase from "./lib/dbConnect" +import connectToDatabase from './lib/dbConnect' export default async (req, res) => { const { method } = req const db = await connectToDatabase() switch (method) { - case "POST": + case 'POST': if (!req.body || !req.body.url || !req.body.cluster) { - res.status(400).json({ success: false, message: "Invalid body" }) - - return + return res.status(400).json({ success: false, message: 'Invalid body' }) } try { await fetch(req.body.url) } catch { - res.status(400).json({ success: false, message: "Invalid URL" }) - - return + return res.status(400).json({ success: false, message: 'Invalid URL' }) } try { @@ -28,19 +24,15 @@ export default async (req, res) => { cluster: req.body.cluster }) } catch { - res.status(400).json({ success: false, message: "Error Inserting to DB" }) - - return + return res.status(400).json({ success: false, message: 'Error Inserting to DB' }) } res.status(200).json({ url: req.body.url }) break - case "DELETE": + case 'DELETE': if (!req.query.url) { - res.status(400).json({ success: false, message: "Invalid body" }) - - return + return res.status(400).json({ success: false, message: 'Invalid body' }) } try { @@ -49,17 +41,14 @@ export default async (req, res) => { }) if (deletedCount == 0) { - res.status(400).json({ success: false, message: "Not Found" }) - - return + return res.status(400).json({ success: false, message: 'Not Found' }) } } catch { - res.status(400).json({ success: false, message: "Error Deleting from DB" }) - - return + return res.status(400).json({ success: false, message: 'Error Deleting from DB' }) } res.status(200).json({ url: req.query.url }) + break default: res.status(404).json({ success: false }) diff --git a/api/lib/dbConnect.js b/api/lib/dbConnect.js index 104d51d..d4aa93d 100644 --- a/api/lib/dbConnect.js +++ b/api/lib/dbConnect.js @@ -1,4 +1,4 @@ -import { MongoClient } from "mongodb" +import { MongoClient } from 'mongodb' const { MONGODB_URI, MONGODB_DB, MONGODB_COLLECTION } = process.env @@ -26,6 +26,7 @@ export default async function connectToDatabase() { } }) } + cached.conn = await cached.promise return cached.conn diff --git a/gatsby-browser.js b/gatsby-browser.js index 5659554..cf9e129 100644 --- a/gatsby-browser.js +++ b/gatsby-browser.js @@ -1 +1 @@ -import "./src/css/base.sass" +import './src/css/base.sass' diff --git a/gatsby-config.js b/gatsby-config.js index 21040fd..4130c36 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -1,23 +1,23 @@ module.exports = { siteMetadata: { - siteUrl: "https://www.pingbot.cf", - title: "Ping Bot", - description: "Keep your apps alive on replit.com or glitch.com" + siteUrl: 'https://www.pingbot.cf', + title: 'Ping Bot', + description: 'Keep your apps alive on replit.com or glitch.com' }, plugins: [ - "gatsby-plugin-react-helmet", - "gatsby-plugin-transition-link", - "gatsby-plugin-sass", + 'gatsby-plugin-react-helmet', + 'gatsby-plugin-transition-link', + 'gatsby-plugin-sass', { - resolve: "gatsby-plugin-manifest", + resolve: 'gatsby-plugin-manifest', options: { - name: "pingbot", - short_name: "pingbot", - start_url: "/", - background_color: "#9517cf", - theme_color: "#9517cf", - display: "minimal-ui", - icon: "src/images/icon.png", // This path is relative to the root of the site. + name: 'pingbot', + short_name: 'pingbot', + start_url: '/', + background_color: '#9517cf', + theme_color: '#9517cf', + display: 'minimal-ui', + icon: 'src/images/icon.png', // This path is relative to the root of the site. } } ] diff --git a/src/axios.js b/src/axios.js index 3000263..609570b 100644 --- a/src/axios.js +++ b/src/axios.js @@ -1,7 +1,7 @@ -import axios from "axios" +import axios from 'axios' const instance = axios.create({ - baseURL: "/api" + baseURL: '/api' }) export default instance diff --git a/src/components/seo.js b/src/components/seo.js index 76c5eeb..921b83b 100644 --- a/src/components/seo.js +++ b/src/components/seo.js @@ -1,7 +1,7 @@ -import React from "react" -import { useStaticQuery, graphql } from "gatsby" -import PropTypes from "prop-types" -import { Helmet } from "react-helmet" +import React from 'react' +import { useStaticQuery, graphql } from 'gatsby' +import PropTypes from 'prop-types' +import { Helmet } from 'react-helmet' function Seo(props) { const { site } = useStaticQuery( @@ -22,26 +22,26 @@ function Seo(props) { return ( \ No newline at end of file diff --git a/src/pages/404.js b/src/pages/404.js index 07b0df2..e84d56d 100644 --- a/src/pages/404.js +++ b/src/pages/404.js @@ -1,7 +1,7 @@ -import React from "react" -import AniLink from "gatsby-plugin-transition-link/AniLink" +import React from 'react' +import AniLink from 'gatsby-plugin-transition-link/AniLink' -import Seo from "../components/seo" +import Seo from '../components/seo' const NotFoundPage = () => { return ( diff --git a/src/pages/add.js b/src/pages/add.js index 89626ba..53d0143 100644 --- a/src/pages/add.js +++ b/src/pages/add.js @@ -1,15 +1,15 @@ -import React from "react" -import AniLink from "gatsby-plugin-transition-link/AniLink" -import { ToastContainer, toast } from "react-toastify" +import React from 'react' +import AniLink from 'gatsby-plugin-transition-link/AniLink' +import { ToastContainer, toast } from 'react-toastify' -import Seo from "../components/seo" -import axios from "../axios" +import Seo from '../components/seo' +import axios from '../axios' -import "../css/url.sass" -import "../css/notifications.sass" +import '../css/url.sass' +import '../css/notifications.sass' const AddURLPage = () => { - const [url, setURL] = React.useState("") + const [url, setURL] = React.useState('') const handleKeypress = e => { if (e.charCode === 13 || e.keyCode === 13) { @@ -23,27 +23,27 @@ const AddURLPage = () => { } const addURL = async () => { - setURL("") + setURL('') - if (url === "") { - return toast("Empty", { - type: "error" + if (url === '') { + return toast('Empty', { + type: 'error' }) } try { - const res = await axios.post("", { + const res = await axios.post('', { url: url, cluster: 1 }) const data = res.data - toast("Added " + data.url, { - type: "success" + toast('Added ' + data.url, { + type: 'success' }) } catch (err) { - let e = "" + let e = '' if (err.response && err.response.data.message) { e = err.response.data.message @@ -52,7 +52,7 @@ const AddURLPage = () => { } toast(e, { - type: "error" + type: 'error' }) } } diff --git a/src/pages/delete.js b/src/pages/delete.js index aa76f90..5a4165d 100644 --- a/src/pages/delete.js +++ b/src/pages/delete.js @@ -1,15 +1,15 @@ -import React from "react" -import AniLink from "gatsby-plugin-transition-link/AniLink" -import { ToastContainer, toast } from "react-toastify" +import React from 'react' +import AniLink from 'gatsby-plugin-transition-link/AniLink' +import { ToastContainer, toast } from 'react-toastify' -import Seo from "../components/seo" -import axios from "../axios" +import Seo from '../components/seo' +import axios from '../axios' -import "../css/url.sass" -import "../css/notifications.sass" +import '../css/url.sass' +import '../css/notifications.sass' const DeleteURLPage = () => { - const [url, setURL] = React.useState("") + const [url, setURL] = React.useState('') const handleKeypress = e => { if (e.charCode === 13 || e.keyCode === 13) { @@ -23,11 +23,11 @@ const DeleteURLPage = () => { } const deleteURL = async () => { - setURL("") + setURL('') - if (url === "") { - return toast("Empty", { - type: "error" + if (url === '') { + return toast('Empty', { + type: 'error' }) } @@ -36,11 +36,11 @@ const DeleteURLPage = () => { const data = res.data - toast("Deleted " + data.url, { - type: "success" + toast('Deleted ' + data.url, { + type: 'success' }) } catch (err) { - let e = "" + let e = '' if (err.response && err.response.data.message) { e = err.response.data.message @@ -49,7 +49,7 @@ const DeleteURLPage = () => { } toast(e, { - type: "error" + type: 'error' }) } } diff --git a/src/pages/index.js b/src/pages/index.js index d253b5c..9f5082a 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -1,7 +1,7 @@ -import React from "react" -import AniLink from "gatsby-plugin-transition-link/AniLink" +import React from 'react' +import AniLink from 'gatsby-plugin-transition-link/AniLink' -import Seo from "../components/seo" +import Seo from '../components/seo' const LoginPage = () => { return ( diff --git a/src/pages/status.js b/src/pages/status.js index ab68808..35eef44 100644 --- a/src/pages/status.js +++ b/src/pages/status.js @@ -1,7 +1,7 @@ -import React from "react" -import AniLink from "gatsby-plugin-transition-link/AniLink" +import React from 'react' +import AniLink from 'gatsby-plugin-transition-link/AniLink' -import Seo from "../components/seo" +import Seo from '../components/seo' const LoginPage = () => { return (