forked from ibrahimsag/read
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocal.js
More file actions
46 lines (40 loc) · 1.03 KB
/
local.js
File metadata and controls
46 lines (40 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import fs from 'fs/promises';
import express from 'express';
import path from 'path';
const app = express();
const port = 3000
const __dirname = path.resolve(path.dirname(''));
app.use('/build', express.static('build'));
app.use('/img', express.static('img'));
app.use('/fonts/', express.static('public/fonts'));
app.use('/js/', express.static('public/js'));
app.use('/', express.static('.'));
app.use(express.json({limit: '50mb'}));
app.get('/favicon.svg', (req, res) => {
res.sendFile(__dirname + '/public/favicon.svg');
})
app.post('/store', (req, res) => {
let d = req.body;
if(!d.key || !d.contents)
{
res.send({ message: 'missing parameters' });
return;
}
fs.writeFile(d.key, d.contents).then(err => {
if(err)
{
console.error(err);
res.send({ message: 'error' });
}
else
{
res.send({ message: 'merhaba' });
}
});
});
app.get('/*', (req, res) => {
res.sendFile(__dirname + '/src/index.html');
})
app.listen(port, () => {
console.log(`listening at http://localhost:${port}`)
})