ReactJS
1import express from 'express';2import ReactDOM from 'react-dom/server';3import {indexTemplate} from "./indexTemplate";4import {App} from "../App";5import axios from "axios";6
7const app = express();8
9app.use('/static', express.static('./dist/client'));10
11app.get('/', (req, res) => {12res.send(13indexTemplate(ReactDOM.renderToString(App())),14);15});16
17app.get('/auth', (req, res) => {18axios.post(19"https://www.reddit.com/api/v1/access_token",20`grant_type=authorization_code&code=${req.query.code}&redirect_uri=http://localhost:3000/auth`,21{22auth: {username: process.env.CLIENT_ID, password: 'vIhiH8tfH_FOCA97OwPJ2ie4ZStDzg'},23headers: {'Content-type': 'application/x-www-form-urlencoded'}24}25)26.then(({data}) => {27res.send(28indexTemplate(ReactDOM.renderToString(App()), data['access_token']),29);30})31.catch(console.error)32
33
34});35
36app.listen(3000, () => {37console.log('Server started on http://localhost:3000');38});