-
Notifications
You must be signed in to change notification settings - Fork 0
Tag testing #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Tag testing #11
Changes from all commits
ef38abe
04e0128
d185b1b
083e118
e7bcbd6
e41c19a
2cbb9a1
7682de7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,6 @@ | ||
| FROM node:10-alpine | ||
|
|
||
| LABEL Delirial elarcadeldelirio@gmail.com | ||
| LABEL version="1.0" | ||
| LABEL description="API backend for testing \ | ||
| and developed on Node+Express+Mongo. \ | ||
| --- Postgresql Stack ----" | ||
| FROM node:10:alpine | ||
| WORKDIR /usr/src/app | ||
| COPY package*.json ./ | ||
| FROM postgresql:alpine | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| build: | ||
| docker: | ||
| web: Dockerfile | ||
| web: node index.js | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| const express = require("express"); | ||
| const bodyParser = require("body-parser"); | ||
| const routes = require("./routes/api"); | ||
| const mongoose = require("mongoose"); | ||
|
|
||
| // Set up express app | ||
| const app = express(); | ||
|
|
||
| // Pass that json data for us, and attach to the request objects | ||
| app.use(bodyParser.json()); | ||
|
|
||
| // Connect to mongoDB | ||
| mongoose.connect("mongodb://localhost:27017/tagdb", { useNewUrlParser: true }); // The db we want to connect to | ||
| mongoose.Promise = global.Promise; // Mongoose Promise version deprecated | ||
|
|
||
| // Initialize routes | ||
| //app.use(routes); | ||
| app.use("/api", routes); | ||
|
|
||
| // Error handling middleware | ||
| app.use((err, req, res, next) => res.status(422).send({error: err})) | ||
|
|
||
| // set the view engine to ejs | ||
| app.set("view engine", "ejs"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this? why a ejs parser?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ejs is used to inject javascript inside html in a easy way. |
||
|
|
||
| // Make express look in the public directory for assets (css/js/img) | ||
| app.use(express.static("public")); | ||
|
|
||
| // Listen to the port set by Heroku | ||
| const port = process.env.PORT; | ||
| app.listen(port || port, () => | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. must be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True xD |
||
| console.log(`Now express listening for requests on port ${port}`) | ||
| ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Tag model | ||
| const mongoose = require("mongoose"); | ||
|
|
||
| // Variable to store our Schema class in | ||
| const Schema = mongoose.Schema; | ||
|
|
||
| // create geolocation Schema | ||
| const GeoSchema = new Schema({ | ||
| type: { | ||
| type: String, | ||
| default: 'Point' | ||
| }, | ||
| coordinates: { | ||
| type: [Number], | ||
| index: '2dsphere' | ||
| } | ||
| }); | ||
|
|
||
| // Create tag Schema | ||
| const TagSchema = new Schema({ | ||
| tag: { | ||
| type: String, | ||
| required: [true, "tag field is required"] | ||
| }, | ||
| geometry: GeoSchema | ||
| // add in geo location | ||
| }); | ||
|
|
||
| // Create Model | ||
| const Tag = mongoose.model("tag", TagSchema); // The Tag model represent the tag collection | ||
| // We want our objects within this collection to be structured based on this TagSchema | ||
| // Mongoose pluralize tag for us, creates a collection called "tags" | ||
|
|
||
| module.exports = Tag; | ||
| // Export this model |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why node index.js and the dockerfile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had stopped the heroku to use docker (it was giving me some errors) so I could deploy the app locally for testing...