Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 5806

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 60k
Author
Asked: November 27, 20242024-11-27T12:40:08+00:00 2024-11-27T12:40:08+00:00

Recycle Code: CNAME & Re-request

  • 60k

Recycle Code

This week, I did some work on the Starchart project where I reuse existing codes to accomplish my tasks. It's always a neat feeling when I find out how I can leverage existing code to achieve a task.

No Duplicate CNAME!

The Starchart project allows user to easily create SSL certificate by taking care of a lot of required steps. Under a certificate, users can have multiple DNS Records.
By design, CNAME DNS Records forward you from one domain to another, so it makes little sense to have two CNAME DNS Records forwarding you from one same domain to two other domains at the same time.

Because of this, we need to prevent users from creating these kind of duplicate CNAME records.

A Small Restriction

I added a piece of code to achieve that:

  const count = await prisma.dnsRecord.count({     where: {       username,       type,       subdomain,       value: type === 'CNAME' ? undefined : value,     },   });  
Enter fullscreen mode Exit fullscreen mode

The project already has some code to check for existing DNS records that are the same with the name, type, and value. Name is the subdomain name. Type is the type of record, such as CNAME. Value would be things like IP address or domain, depending on the type of DNS record.

Most of the relevant code already exist to check for count of duplicate DNS record, and I ended up adding a condition to not care about whether value is the same for CNAME records. As long as an existing CNAME record belongs to the same user and has same subdomain, another one counts as a duplicate. The value doesn't matter. These two criteria are chosen because username and subdomain name are used to create the domain name where a CNAME record would redirect people from, in this project.
Recall that we don't want to redirect from one domain to multiple domain. This is why we check for CNAME records with same user and subdomain.

It utilizes Prisma's count to do the counting in the database. where specifies what criteria for a row to count.

Re-request Certificate

Speaking of certificate, I also did a PR with a teammate together with peer programming, to add the ability for users to re-request a new certificate when it's about to expire.

What we did

The code checks for whether a certificate's validTo date is less than 30 days from present. If so, a re-request button will become available on the certificate page to allow the user to request another certificate.
Because we already have existing code to allow users to request their first certificate, we simply use/trigger that code again for the button.

Code Snippet for the button:

              <Flex justifyContent="flex-end">                 <Form method="post" onSubmit={() => setIsDisabled(true)}>                   <IconButton                     type="submit"                     aria-label="renew-certificate"                     icon={<RepeatIcon />}                     backgroundColor="transparent"                     color="black"                     _hover={{ backgroundColor: 'brand.500', color: 'white' }}                     isDisabled={isDisabled}                   />                 </Form>               </Flex> 
Enter fullscreen mode Exit fullscreen mode

Because the certificate request code is under an action function build with remix.js, and it's triggered by submit, we simply make this new button submit to reuse that code.

We did found out a minor bug where the program was only recognizing the second newest certificate for a user, because the code was sorting certificates by validTo date in descending order, to fetch the newest one, but a really new one would not have that field filled out for a short period. This caused the new certificate to be placed at the bottom of the sorting and not be select as the current certificate.

Peer programming

It's interesting sitting with another developer to work on code together. You get tow different perspectives, and you can learn form each other, whether it's expertise with tools and languages, coding style, or new ideas.

Because I'm unfamiliar with the front-end of the project, it was very helpful to sit with another developer who is familiar with that area.
He walked me through how the area of the front-end code we wanted to work on is constructed, and we put our ideas together to figure out how to tackle the issue.

javascriptopensourcewebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    ES6 - A beginners guide - Template Literals

    • 0 Answers
  • Author

    Understanding Higher Order Functions in JavaScript.

    • 0 Answers
  • Author

    Build a custom video chat app with Daily and Vue.js

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.