Advertisement
Guest User

Untitled

a guest
Oct 7th, 2022
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const express = require('express');
  2. const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
  3.  
  4. const router = express.Router();
  5.  
  6. router.post('/api/users/register', async (req, res) => {
  7.  
  8.     try{
  9.         const registerResponse = await fetch(`${process.env.API_URL}/api/users/register`, {
  10.             method: 'POST',
  11.             Headers: {
  12.                 Accept: 'application/json',
  13.                 'Content-Type': 'application/json'
  14.             },
  15.             body: JSON.stringify({
  16.                 first_name: 'test',
  17.                 last_name: 'test',
  18.                 email: 'test@test.pl',
  19.                 password: 'qazwsx123#RF',
  20.             })
  21.         })
  22.  
  23.         const data = await registerResponse.json();
  24.  
  25.         return res.status(registerResponse.status).json(data)
  26.     } catch(err){
  27.         return res.status(500).json({
  28.             error: 'Something went wrong when registering account'
  29.         });
  30.     }
  31. });
  32.  
  33. module.exports = router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement