Skip to content
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

Tag testing #11

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
FROM node:10-alpine

LABEL Delirial [email protected]
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


2 changes: 1 addition & 1 deletion heroku.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
build:
docker:
web: Dockerfile
web: node index.js
Copy link
Contributor

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?

Copy link
Contributor Author

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...

33 changes: 33 additions & 0 deletions 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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this? why a ejs parser?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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, () =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must be app.listen(port || 3000) or something like that for case that PORT ENV variable not be setted

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True xD

console.log(`Now express listening for requests on port ${port}`)
);
35 changes: 35 additions & 0 deletions models/tag.js
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
Empty file added models/tag2.js
Empty file.
Loading