мне нужно закончить server.js чтобы проект заработал. у меня получилось только часть выполнить. остались операции в конце fetch update delete Save, помогите пожалуйста
server.js
const express = require("express");
const app = express();
const cors = require("cors");
const session = require("express-session");
const cookieParser = require("cookie-parser");
const whitelist = ['http://localhost',
'http://localhost:3000',
'http://localhost:80'];
const corsOptions = {
credentials: true,
origin: (origin, callback) => {
console.log(origin);
if ( whitelist.includes(origin) ) {
return callback(null, true)
}
callback(new Error('Not allowed by CORS'));
}
}
app.use(cors());
app.set('trust proxy', 1)
app.use(session({
secret: "Wok Tow3l",
resave: false,
saveUninitialized: true,
cookie: { secure: true }
}));
var sess = {
secret: 'Wok Tow3l',
cookie: {}
}
sess.cookie.secure = true // serve secure cookies
app.use(session(sess))
app.use(session({ secret: 'Wok Tow3l', cookie: { maxAge: 60000 }}))
app.use(cookieParser());
app.get('/ping', function (req, res, next) {
res.send('target ' + req.session + ' ');
req.sess.destroy(function(err) {
})
})
app.post('/ping',(req,res) => {
sess = req.session;
sess.cookie = req.target;
res.end('done');
});
app.use('/', router);
app.get("/ping", (req, res) => {
res.send('Pong!');
});
/* Save a new Todo */
app.post("/save/:target", (req, resp) => {
});
/* Fetch the list of :target Todo item(s) */
app.get("/get/:target", (req, resp) => {
// You need to complete this
});
/* update a Todo */
app.put("/:target/:id", (req, resp) => {
// You need to complete this
});
/* delete a Todo */
app.delete("/:target/:id", (req, resp) => {
// You need to complete this
});
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Todo (server) is listening at http://localhost:${port}`);
});