38 lines
817 B
JavaScript
38 lines
817 B
JavaScript
const express = require('express');
|
|
const cors = require('cors');
|
|
const fs = require('fs/promises');
|
|
|
|
const PORT = process.env.PORT || 8080;
|
|
|
|
const app = express();
|
|
|
|
app.use(cors());
|
|
app.use(express.json());
|
|
app.use(express.urlencoded({ extended: false }));
|
|
|
|
app.get('/form', async (req, res) => {
|
|
const html = await fs.readFile('public/index.html');
|
|
|
|
res.setHeader('Content-Type', 'text/html');
|
|
res.send(html);
|
|
res.end();
|
|
});
|
|
|
|
app.use(function (req, res) {
|
|
const info = {
|
|
method: req.method,
|
|
url: req.url,
|
|
headers: req.headers,
|
|
body: req.body,
|
|
};
|
|
console.log(info);
|
|
|
|
res.setHeader('Content-Type', 'application/plain');
|
|
res.write(JSON.stringify(info, null, 2));
|
|
res.end();
|
|
});
|
|
|
|
app.listen(PORT, function () {
|
|
console.log(`CORS-enabled web server listening on port ${PORT}`);
|
|
});
|