Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
agetic
sitio-firebase
Commits
7a0de768
Commit
7a0de768
authored
Mar 18, 2020
by
Adrian
Browse files
Merge branch 'master' of gitlab.agetic.gob.bo:dbarra/sitio-firebase
parents
abe9df70
2e2ae7a6
Changes
3
Hide whitespace changes
Inline
Side-by-side
INSTALL.md
View file @
7a0de768
# BACKEND
## Cambiar la clave con la que se codifican los tokens en el archivo config.js en el atributo SECRET_TOKEN
## Instalar las dependencias:
con npm i
...
...
backend/config.js
View file @
7a0de768
...
...
@@ -2,7 +2,7 @@
const
config
=
{
SECRET_TOKEN
:
'
AGETIC_SUPER_SECRET_
'
,
autorizacion
:
'
AAAA
i0s6FB
w:APA91b
GF_pnVmZRW0l7X7pgLvPcmbRL14HdoqzcklDxu6aO7z7ui7_JKofMf_U4LPO0xvkvVPleN8QIdVjIQ1WMvSLwV0I1R28QWzNaKdRAD7MBd31h2W9z_bf-p_AJg7I_22P67gIzy
'
,
autorizacion
:
'
AAAA
PEVgJj
w:APA91b
FN3ZmibnDgcs6YOyf8CgwxF0ZPkUlZvncHkuFsIozznmYAcvKRnR7rFyDIFpYdntMZzbzWj4QYtOXGjXdxmRt0R5jFfw15LCXASK9fJCqdoItWb4dcdiDRGifQUOeePDdyVq_v
'
,
usuarios
:
[
{
usuario
:
'
admin
'
,
...
...
backend/server.js
View file @
7a0de768
...
...
@@ -28,19 +28,19 @@ app.use(morgan(function (tokens, req, res) {
app
.
use
(
bodyParser
.
json
({
limit
:
'
10mb
'
}));
app
.
use
(
cors
(
corsOptions
));
async
function
mensajeExito
(
res
,
datos
)
{
return
res
.
status
(
200
).
json
({
async
function
mensajeExito
(
res
,
mensaje
=
'
OK
'
,
codigo
=
200
,
datos
)
{
return
res
.
status
(
codigo
).
json
({
finalizado
:
true
,
mensaje
:
'
OK
'
,
datos
:
datos
mensaje
:
mensaje
,
datos
})
}
async
function
mensajeError
(
res
,
mensaje
Error
)
{
return
res
.
status
(
400
).
json
({
async
function
mensajeError
(
res
,
mensaje
=
'
Ocurrio un error desconocido.
'
,
codigo
=
400
,
datos
=
null
)
{
return
res
.
status
(
codigo
).
json
({
finalizado
:
false
,
mensaje
:
mensaje
Error
,
datos
:
null
mensaje
:
mensaje
,
datos
})
}
...
...
@@ -58,10 +58,13 @@ async function AuthorizationMiddleware (req, res, next) {
req
.
usuario
=
decoded
.
usuario
next
();
}
catch
(
error
)
{
mensajeError
(
res
,
error
.
message
);
mensajeError
(
res
,
error
.
message
,
401
);
}
}
app
.
get
(
'
/status
'
,
async
function
(
req
,
res
)
{
mensajeExito
(
res
,
'
Funcionando correctamente.
'
,
200
,
''
);
});
app
.
post
(
'
/login
'
,
async
function
(
req
,
res
)
{
try
{
...
...
@@ -80,15 +83,18 @@ app.post('/login', async function (req, res) {
if
(
!
existe
)
{
throw
new
Error
(
'
El usuario no existe
'
);
}
mensajeExito
(
res
,
respuesta
);
mensajeExito
(
res
,
'
Login correcto
'
,
200
,
respuesta
);
}
catch
(
error
)
{
mensajeError
(
res
,
error
.
message
);
mensajeError
(
res
,
error
.
message
,
400
);
}
});
app
.
post
(
'
/send
'
,
AuthorizationMiddleware
,
async
function
(
req
,
res
)
{
try
{
const
{
titulo
,
text
}
=
req
.
body
;
if
(
!
titulo
||
!
text
)
{
throw
new
Error
(
'
Debe enviar los parametros necesarios.
'
);
}
const
init
=
{
method
:
'
POST
'
,
url
:
'
https://fcm.googleapis.com/fcm/send
'
,
...
...
@@ -97,22 +103,28 @@ app.post ('/send', AuthorizationMiddleware, async function (req, res) {
'
Content-Type
'
:
'
application/json
'
,
},
data
:
{
notification
:
{
to
:
'
/topics/all
'
,
notification
:
{
body
:
text
,
title
:
titulo
,
text
:
text
,
badge
:
1
,
sound
:
'
default
'
},
data
:
{
foo
:
'
bar
'
badge
:
'
1
'
},
priority
:
'
High
'
,
to
:
''
priority
:
'
High
'
}
}
const
repsuesta
=
await
axios
(
init
);
// const repsuesta = {};
mensajeExito
(
res
,
repsuesta
.
data
);
// const repsuesta = {
// data: {
// to: '/topics/all',
// notification : {
// body : text,
// title: titulo,
// badge: '1'
// },
// priority: 'High'
// }
// };
mensajeExito
(
res
,
'
Notificación enviada correctamente.
'
,
200
,
repsuesta
.
data
);
}
catch
(
error
)
{
if
(
error
.
response
)
{
console
.
log
(
'
____________________________________________________________________________________________________ERROR_RESPONSE_
'
);
...
...
@@ -123,7 +135,7 @@ app.post ('/send', AuthorizationMiddleware, async function (req, res) {
console
.
log
(
'
___________________________________________________________________________________________________ERROR_MESSAGE_
'
);
console
.
log
(
error
.
message
);
console
.
log
(
'
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ERROR_MESSAGE_
'
);
mensajeError
(
res
,
error
.
message
);
mensajeError
(
res
,
error
.
message
,
401
);
}
}
})
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment