Skip to content
Snippets Groups Projects
Commit 12a80d5f authored by priagungs's avatar priagungs
Browse files

init backend

parent bd5c2140
Branches
No related merge requests found
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Typescript v1 declaration files
typings/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
# next.js build output
.next
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const admin = require('firebase-admin');
const serviceAccount = require('./chatman-a99e6-firebase-adminsdk-e2t5v-36aaaada49.json');
const indexRouter = require('./routes/index');
const usersRouter = require('./routes/users');
const app = express();
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'https://chatman-a99e6.firebaseio.com/'
});
let registrationToken = "dhoxHmhVQzo:APA91bGt3zNCA0OdxZ4PV2HCiWqFRSaPftZr6-rKB53O_ZSnTiBDB_YV8vSbaCjXLYzy_pkhd2VBppm6ohXcePhhPC-h4jXA2IwPADqmauhpN4_6eWEAmiBiPPw2WOjsP3CSIW6i569w";
let message = {
notification: {
title: 'Hi :*',
body: 'Pakabar ?'
},
token: registrationToken
}
app.get('/send', function(req, res) {
admin.messaging().send(message)
.then(response => {
console.log('Success : ' + response)
res.send('success');
})
.catch(err => {
console.log('Error : ' + err)
res.send('error');
});
});
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
app.use('/users', usersRouter);
app.listen(3000, function() {
console.log('chatman running at port 3000');
});
module.exports = app;
#!/usr/bin/env node
/**
* Module dependencies.
*/
var app = require('../app');
var debug = require('debug')('backend:server');
var http = require('http');
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
/**
* Create HTTP server.
*/
var server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val) {
var port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}
/**
* Event listener for HTTP server "error" event.
*/
function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}
var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}
/**
* Event listener for HTTP server "listening" event.
*/
function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
{
"type": "service_account",
"project_id": "chatman-a99e6",
"private_key_id": "36aaaada49b1771324c071d95a3908da21aac7c2",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDJPtc3xjEGdEs7\n5YqYgDaZHLZHe9ZVQFbfCeVWVkfxVIzEHVgYK08+tIawmi2LXTVLW4f+cFahLl9A\nemtyD0jBFy74x65eLE8OtpOgGz7oX7Kua+eZqlwKeqL+hxcz3tY+099NW5mKheTc\nBX4FJsXppvm/7jHMn2hz5ul4I7+PuWAopNixgUMXiDwI7Y7pXdaSzu0G0HS7xBJ5\nNOyhkYgmj5toYI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flOWeB4x2dqEQ\n/tcZ6UTpgvC9eSuYJWn7erYHnG6XgXb+dK0W2noCbXOpFI9gbLdgr7M3iXmA4Bpq\n6YZfcwkbDs4kyn8Lq5W2lXJVlnNMzaiJHcmVIq8ZAoGAaOlb2NoZ80gl4l7WqS/G\nJkyU1qbq9xSZ456clPbA/h3HxRFJbDs6EwGXEoBg+ow2l2stNdQkjDyQ2i+yRPNo\n3A9g35zaCYDREy5W5As3en76Uq71ABbg7fFQAsu7eqicg4nsWA/Qx/CV6KcbzEZE\npypz9utdRmkQWnQAivenfR4=\n-----END PRIVATE KEY-----\n",
"client_email": "firebase-adminsdk-e2t5v@chatman-a99e6.iam.gserviceaccount.com",
"client_id": "111555813811256028469",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-e2t5v%40chatman-a99e6.iam.gserviceaccount.com"
}
This diff is collapsed.
{
"name": "backend",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"express": "~4.16.0",
"firebase-admin": "^7.0.0",
"morgan": "~1.9.0"
}
}
<html>
<head>
<title>Express</title>
<link rel="stylesheet" href="/stylesheets/style.css">
</head>
<body>
<h1>Express</h1>
<p>Welcome to Express</p>
</body>
</html>
body {
padding: 50px;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}
a {
color: #00B7FF;
}
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
module.exports = router;
var express = require('express');
var router = express.Router();
/* GET users listing. */
router.get('/', function(req, res, next) {
res.send('respond with a resource');
});
module.exports = router;
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment