Meteor and Hapi together?

Hi,
I am trying to use one database and be able to have two different nodejs (one meteor, one hapi). The meteor will handle the front end and allow CRUD to the database from a user.
The Hapi would allow for REST API.

I see them both as great in their own way. I want to know if I can do this, and whether Meteor should send REST API to HAPI or if I can give them both access directly to the database. How bad would conflicts/collisions be? Is there a way to avoid conflicts/collisions?

I like developing on Meteor so I’d like to continue using it for an admin platform.

Thanks

Adding a REST endpoint to Meteor is very doable. Here’s an example for HelloSign:

import multer from 'multer';

const helloSignAccountCallBackURL = 'https://my_web_site.com/ReceiveCallsFromHelloSign';
const hellosign = require('hellosign-sdk')({key: 'my_key'});
hellosign.account.update({
	callback_url: helloSignAccountCallBackURL
}).then((res) => {
	console.log('success setting hellosign account callback url');
}).catch((err) => {
	console.log('error setting hellosign account callback url');
	console.log(err)
});

//REST API FOR HELLOSIGN
const callback = multer({dest: './uploads'});

// Mount the middleware first so it's run first
WebApp.connectHandlers.use('/ReceiveCallsFromHelloSign', callback.single('json'));

// Then mount the user handler
WebApp.connectHandlers.use('/ReceiveCallsFromHelloSign', (req, res, next) => {
	res.setHeader('Content-Type', 'text/html');
	res.setHeader('X-Foo', 'bar');
	res.writeHead(200, {'Content-Type': 'text/plain'});
	res.end('Hello API Event Received');

	const data = req.body.json;
	const events = JSON.parse(data);
	const eventType = events.event.event_type;
	const signatureRequestId = events.signature_request.signature_request_id;

	switch (eventType) {
		case 'signature_request_sent':
			console.log(`Signature request ${signatureRequestId} has been sent.`);
			break;
		case 'signature_request_viewed':
			console.log(`Signature request ${signatureRequestId} has been viewed.`);
			break;
		case 'signature_request_downloadable':
			console.log(`Signature request ${signatureRequestId} is downloadable.`);
			break;
		case 'signature_request_signed':
			const signatureIdToMatch = events.signature_request.response_data[0].signature_id;
			console.log(`Signature request ${signatureIdToMatch} has been signed.`);
			break;
		case 'signature_request_declined':
			console.log(`Signature request ${signatureRequestId} has been declined.`);
			break;
		default:
			console.log('');
			break;
	}
});
1 Like