This repo contains starter code to deploy a nodeJS ExpressJS API on OpenShit. If followed correctly you will have CRUD endpoints on collections within MongoDB
- Connected to campus VPN
- Github Account, you can use GitHub's code editor to change the MongoDB IP address later on
- Sign up for Carolina Cloud Apps | This step will only take a second
- Fork this repo to your github account
- Head to the Topology Tab under the Developer View
- Select Database from the tiles that appear
- Select MongoDB from the tiles that appear and hit instantiate template on the modal that opens
- Accept all default values in the form, for the purpose of this demonstration you can use email and password settings as follows. Please make sure you remember or note these values as you will need them later
- Hit create
- Once the status of the pod shows up as active, head to the resource tab, and then hit view logs on the pod, followed by the terminal tab
- In the terminal type the following command
mongo -u "admin" -p "Admin123" admin
- If the connection is successful you should see this in the terminal
MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017/admin
MongoDB server version: 3.6.3
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
- Go back to the topology and click the mongodb pod, from there hit the mongodb service
- Note the IP of the cluster, and update the IP address of the database connection in this repo under config/database.config.js
- Head to the Topology tab under the Developer view
- Right click anywhere and select add to project from catalog
- Search nodeJS and hit the first tile and hit create application
- Provide the Github repo link of your forked repo, this repo should contain the updated IP of your mongodb database
- Hit Create, click on the newly created pod, and wait for the build to finish
- Visit the endpoint, by clicking the link on the pod
- if you have followed all steps correctly you should see the following output in the browser
{"welcome":"This is a backend starter api based on an express api connected to mongodb, on the OpenShift container platform"}
- Congratulations your API is now live, modify the routes and model for your use case. Default CRUD implementations have been provided under app/controllers and you can play around with them in Postman.
- Download MongoDB Compass, use this to remotely connect to the DB. You can use the same connection string as in the database config
- Download the OpenShift CLI, can be used to emulate pods and route ports for local testing
- Heres how to remotely connect to MongoDB over localhost
oc get pods
This will return output like
NAME READY STATUS RESTARTS AGE
mongodb-1-XXXXX 1/1 Running 0 12h
my-node-app-10-build 0/1 Completed 0 10h
Grab the mongodb pod name from the output. From here you can remote sh using the following command
oc rsh mongodb-1-XXXXX
To connect to mongodb via local host setup port forwarding, this will allow you to send traffic to mongodb over localhost:34000. You can also replace the ip in the database config with localhost:34000 to test connections locally
oc port-forward mongodb-1-XXXXX 34000:27017
- Enable SSL, ssl can be enabled in Administrator view by going to Networking, Routes, name of your node application, and adding this tls argument to your YAML configuration under the spec section
tls:
termination: edge
insecureEdgeTerminationPolicy: None