备忘录提供跨域访问
This commit is contained in:
parent
57fe592d02
commit
b823f2ef95
|
|
@ -1407,12 +1407,21 @@ api.post('/addNote', function(req, res) {
|
||||||
|
|
||||||
api.get('/notes', function(req, res) {
|
api.get('/notes', function(req, res) {
|
||||||
console.log("getNotes username = ", req.session.username);
|
console.log("getNotes username = ", req.session.username);
|
||||||
|
res.header('Access-Control-Allow-Origin', '*');
|
||||||
|
res.header('Access-Control-Allow-Headers', 'Content-Type');
|
||||||
|
res.header('Access-Control-Allow-Methods', '*');
|
||||||
|
|
||||||
var params = req.query;
|
var params = req.query;
|
||||||
if (!params.shareNote && !req.session.user) {
|
if (!params.shareNote && !req.session.user) {
|
||||||
res.send(401);
|
res.send(401);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (params.shareNote) {
|
if (params.shareNote) {
|
||||||
|
if(params.json) {
|
||||||
|
db.getNote(params.shareNote)
|
||||||
|
.then((data) => res.json(data))
|
||||||
|
.catch((err) => console.log('notes', err));
|
||||||
|
} else {
|
||||||
db.getNote(params.shareNote)
|
db.getNote(params.shareNote)
|
||||||
.then((data) => res.send(`
|
.then((data) => res.send(`
|
||||||
<body style="margin:0px;height:100%;">
|
<body style="margin:0px;height:100%;">
|
||||||
|
|
@ -1433,6 +1442,7 @@ api.get('/notes', function(req, res) {
|
||||||
</div>
|
</div>
|
||||||
</body>`))
|
</body>`))
|
||||||
.catch((err) => console.log('notes', err));
|
.catch((err) => console.log('notes', err));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
params.user_id = req.session.user.id;
|
params.user_id = req.session.user.id;
|
||||||
db.getNotes(params)
|
db.getNotes(params)
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ drop table if exists notes;
|
||||||
CREATE TABLE `notes` (
|
CREATE TABLE `notes` (
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT, -- id
|
`id` int(11) NOT NULL AUTO_INCREMENT, -- id
|
||||||
`user_id` int(11) NOT NULL, -- 用户id
|
`user_id` int(11) NOT NULL, -- 用户id
|
||||||
`content` varchar(8092) DEFAULT NULL, -- 备忘内容
|
`content` text DEFAULT NULL, -- 备忘内容
|
||||||
`tag_id` int(11) DEFAULT NULL, -- 分类id
|
`tag_id` int(11) DEFAULT NULL, -- 分类id
|
||||||
`created_at` datetime DEFAULT now(), -- 创建时间
|
`created_at` datetime DEFAULT now(), -- 创建时间
|
||||||
`public` tinyint(4) DEFAULT '1', -- 是否公开 1 公开,0 不公开
|
`public` tinyint(4) DEFAULT '1', -- 是否公开 1 公开,0 不公开
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue