Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
SunWuyuan committed Jul 2, 2024
1 parent 06b69f4 commit c8716cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ var corsOptions = {
if (process.env.corslist.indexOf(origin) !== -1 || !origin) {
callback(null, true);
} else {
callback(new Error());
callback(new Error('Not allowed by CORS'));
}
},
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
preflightContinue: false,
optionsSuccessStatus: 204,
optionsSuccessStatus: 200,
credentials: true,
};
app.use(cors(corsOptions)); // 应用CORS配置函数
Expand Down Expand Up @@ -111,6 +111,7 @@ global.dirname = __dirname;
http.createServer(app).listen(3000, "0.0.0.0", function () {
console.log("Listening on http://localhost:3000");
}); // 平台总入口
app.options('*', cors())
app.all("*", function (req, res, next) {
//console.log(req.method +' '+ req.url + " IP:" + req.ip);

Expand Down
10 changes: 6 additions & 4 deletions server/router_scratch.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ router.get("/projectinfo", function (req, res) {
` ow_Users.motto AS author_motto` +
` FROM scratch ` +
` LEFT JOIN ow_Users ON (ow_Users.id=scratch.authorid) ` +
` WHERE scratch.id=${req.query.id} AND scratch.state>=1 LIMIT 1`;
` WHERE scratch.id=${req.query.id} AND (scratch.state>=1 or scratch.authorid=${res.locals.userid}) LIMIT 1`;
DB.query(SQL, function (err, SCRATCH) {
if (err || SCRATCH.length == 0) {
res.locals.tip = { opt: "flash", msg: "项目不存在或未发布" };
res.render("404.ejs");
res.send({code:404,status:"404",msg:"项目不存在或未发布"})
return;
}

Expand All @@ -181,7 +181,7 @@ router.get("/projectinfo2", function (req, res) {
DB.query(SQL, function (err, SCRATCH) {
if (err || SCRATCH.length == 0) {
res.locals.tip = { opt: "flash", msg: "项目不存在或未发布" };
res.render("404.ejs");
res.send({code:404,status:"404",msg:"项目不存在或未发布"})
return;
}
res.locals["is_author"] =
Expand Down Expand Up @@ -613,8 +613,10 @@ router.post("/projects", function (req, res) {
if (req.query.title) {
title = req.query.title;
}


var INSERT = `INSERT INTO scratch (authorid, title, src) VALUES (${res.locals.userid}, ?, ?)`;
var VAL = [title, `${JSON.stringify(req.body)}`];
var VAL = [title, `${JSON.stringify(req.body.work||req.body)}`];
DB.qww(INSERT, VAL, function (err, newScratch) {
if (err || newScratch.affectedRows == 0) {
res.send(404);
Expand Down

0 comments on commit c8716cc

Please sign in to comment.