server.js
808 Bytes
const fs = require('fs');
const path = require("path");
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const port = process.env.PORT || 5000;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true}));
let scriptReceived = "";
app.get('/api/:script', (req, res) => {
res.send(
scriptReceived
);
});
app.post('/api/:script', (req, res) => {
scriptReceived = req.body.script;
});
app.use(express.static(path.join(__dirname, './client/build'))); // μ μ νμΌλ‘ λ°κΏμ§ React[front-end]λ₯Ό Express μλ²λ‘λ§ μ΄μ©ν μ μλλ‘ ν΄μ€
app.get('*', (req, res, next)=>{
res.sendFile(path.join(__dirname, "./client/build", "index.html"));
});
app.listen(port, () => console.log(`Listening on port ${port}`));