-
Notifications
You must be signed in to change notification settings - Fork 0
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
Ona custom changes #2
base: master
Are you sure you want to change the base?
Changes from 14 commits
9ac763c
0017195
ba5053d
094cbf7
93fab2c
6585085
f266c0d
3947bb2
d4cc051
a2868e9
8ec0889
9ac5039
db113da
0013eaf
8bd36bb
91e4743
5bbb949
0cac1e6
4e5644b
6d3247d
e73472c
d9529c0
888ae3f
17720f5
5970e40
8bd6b62
c3d0955
baa45a1
c84c1b6
7826310
c7a2696
f14a777
72487d2
d63a926
ddfe73b
56319fb
f257308
abafc0e
9f02a8f
3c0eb21
7ca685c
c94086d
283e96b
62c8baf
ecd9ef9
9ddcea8
1fe5086
b7aac83
e121b96
4c6788f
967f090
e5e39f5
e164c74
0ba5cba
7a1021d
0bf11b9
08f0c50
2b5cb0c
b9d74cd
6e1fda3
1cdfd30
d852acc
d4aac19
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,2 +1,3 @@ | ||
node_modules | ||
npm-debug.log | ||
.env |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: build and push image to dockerhub | ||
on: | ||
push: | ||
tags: | ||
- '[0-9]+\.[0-9]+\.[0-9]+' | ||
jobs: | ||
main: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Get the version | ||
id: get-version-release | ||
run: echo "version=${GITHUB_REF_NAME#refs/heads}" >> $GITHUB_ENV | ||
|
||
- name: Checkout to version | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ env.version }} | ||
|
||
- name: Login to DockerHub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | ||
|
||
- name: Build and push | ||
id: docker-build | ||
uses: docker/build-push-action@v3 | ||
with: | ||
context: . | ||
file: Dockerfile | ||
platforms: linux/amd64 | ||
push: true | ||
tags: | | ||
onaio/dirt-tile-server:${{ env.version }} | ||
|
||
- name: Image digest | ||
run: echo ${{ steps.docker-build.outputs.digest }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,86 +10,129 @@ if ("SERVER_LOGGER" in process.env) { | |
} | ||
} | ||
|
||
const fastify = require("fastify")({ logger: logger }) | ||
const axios = require("axios"); | ||
|
||
// EXIT IF POSTGRES_CONNECTION ENV VARIABLE NOT SET | ||
if (!("POSTGRES_CONNECTION" in process.env)) { | ||
throw new Error("Required ENV variable POSTGRES_CONNECTION is not set. Please see README.md for more information."); | ||
} | ||
async function build() { | ||
const fastify = require("fastify")({ logger: logger }); | ||
await fastify.register(require('@fastify/express')); | ||
const queryString = require("query-string"); | ||
fastify.use((req, res, done) => { | ||
reqParams = req.url.split("?")[1]; | ||
const parsedReqParams = queryString.parse(reqParams); | ||
const formId = parsedReqParams.form_id; | ||
tempToken = parsedReqParams.temp_token; | ||
if (formId) { | ||
axios | ||
.get(`${process.env.FORMS_ENDPOINT}${formId}.json`, { | ||
headers: tempToken && tempToken.length > 0 ? { | ||
Authorization: `TempToken ${tempToken}`, | ||
} : {}, | ||
}) | ||
.then((res) => { | ||
if (res && res.status === 200) { | ||
done(); | ||
} else { | ||
done("Forbidden"); | ||
} | ||
}) | ||
.catch((error) => { | ||
console.log(error) | ||
done(error.detail); | ||
}); | ||
} else if ("/health-check" == req.url) { | ||
done() | ||
} else { | ||
done("Authentication Failure"); | ||
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. Can we also add a status code (401) 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. I couldn't find how to do this from fastify documentation |
||
} | ||
}); | ||
|
||
// EXIT IF POSTGRES_CONNECTION ENV VARIABLE NOT SET | ||
if (!("POSTGRES_CONNECTION" in process.env)) { | ||
throw new Error("Required ENV variable POSTGRES_CONNECTION is not set. Please see README.md for more information."); | ||
} | ||
|
||
// POSTGRES CONNECTION | ||
fastify.register(require('@fastify/postgres'), { | ||
connectionString: process.env.POSTGRES_CONNECTION | ||
}) | ||
// POSTGRES CONNECTION | ||
fastify.register(require('@fastify/postgres'), { | ||
connectionString: process.env.POSTGRES_CONNECTION | ||
}) | ||
|
||
// COMPRESSION | ||
// add x-protobuf | ||
fastify.register( | ||
require('@fastify/compress'), | ||
{ customTypes: /x-protobuf$/ } | ||
) | ||
// COMPRESSION | ||
// add x-protobuf | ||
fastify.register( | ||
require('@fastify/compress'), | ||
{ customTypes: /x-protobuf$/ } | ||
) | ||
|
||
// CACHE SETTINGS | ||
fastify.register( | ||
require('@fastify/caching'), { | ||
// CACHE SETTINGS | ||
fastify.register( | ||
require('@fastify/caching'), { | ||
privacy: process.env.CACHE_PRIVACY || 'private', | ||
expiresIn: process.env.CACHE_EXPIRESIN || 3600, | ||
serverExpiresIn: process.env.CACHE_SERVERCACHE | ||
}) | ||
|
||
// CORS | ||
fastify.register(require('@fastify/cors'), { origin: JSON.parse(process.env.CORS_ORIGINS) }) | ||
|
||
// OPTIONAL RATE LIMITER | ||
if ("RATE_MAX" in process.env) { | ||
fastify.register(import('@fastify/rate-limit'), { | ||
max: process.env.RATE_MAX, | ||
timeWindow: '1 minute' | ||
}) | ||
} | ||
) | ||
|
||
// CORS | ||
fastify.register(require('@fastify/cors')) | ||
// INITIALIZE SWAGGER | ||
fastify.register(require('@fastify/swagger'), { | ||
exposeRoute: true, | ||
routePrefix: '/', | ||
swagger: { | ||
"info": { | ||
"title": "Dirt-Simple PostGIS HTTP API", | ||
"description": "The Dirt-Simple PostGIS HTTP API is an easy way to expose geospatial functionality to your applications. It takes simple requests over HTTP and returns JSON, JSONP, or protobuf (Mapbox Vector Tile) to the requester. Although the focus of the project has generally been on exposing PostGIS functionality to web apps, you can use the framework to make an API to any database.", | ||
"version": process.env.npm_package_version || "" | ||
}, | ||
"externalDocs": { | ||
"url": "https://github.com/tobinbradley/dirt-simple-postgis-http-api", | ||
"description": "Source code on Github" | ||
}, | ||
"schemes": [ | ||
"http", | ||
"https" | ||
], | ||
"tags": [{ | ||
"name": "api", | ||
"description": "code related end-points" | ||
}, { | ||
"name": "feature", | ||
"description": "features in common formats for direct mapping." | ||
}, { | ||
"name": "meta", | ||
"description": "meta information for tables and views." | ||
}] | ||
} | ||
}) | ||
|
||
// OPTIONAL RATE LIMITER | ||
if ("RATE_MAX" in process.env) { | ||
fastify.register(import('@fastify/rate-limit'), { | ||
max: process.env.RATE_MAX, | ||
timeWindow: '1 minute' | ||
// ADD ROUTES | ||
fastify.register(require('@fastify/autoload'), { | ||
dir: path.join(__dirname, 'routes') | ||
}) | ||
} | ||
|
||
// INITIALIZE SWAGGER | ||
fastify.register(require('@fastify/swagger'), { | ||
exposeRoute: true, | ||
routePrefix: '/', | ||
swagger: { | ||
"info": { | ||
"title": "Dirt-Simple PostGIS HTTP API", | ||
"description": "The Dirt-Simple PostGIS HTTP API is an easy way to expose geospatial functionality to your applications. It takes simple requests over HTTP and returns JSON, JSONP, or protobuf (Mapbox Vector Tile) to the requester. Although the focus of the project has generally been on exposing PostGIS functionality to web apps, you can use the framework to make an API to any database.", | ||
"version": process.env.npm_package_version || "" | ||
}, | ||
"externalDocs": { | ||
"url": "https://github.com/tobinbradley/dirt-simple-postgis-http-api", | ||
"description": "Source code on Github" | ||
}, | ||
"schemes": [ | ||
"http", | ||
"https" | ||
], | ||
"tags": [{ | ||
"name": "api", | ||
"description": "code related end-points" | ||
}, { | ||
"name": "feature", | ||
"description": "features in common formats for direct mapping." | ||
}, { | ||
"name": "meta", | ||
"description": "meta information for tables and views." | ||
}] | ||
} | ||
}) | ||
fastify.get('/health-check', { logLevel: 'warn' }, (request, reply) => { | ||
reply.send("healthy"); | ||
}) | ||
|
||
// ADD ROUTES | ||
fastify.register(require('@fastify/autoload'), { | ||
dir: path.join(__dirname, 'routes') | ||
}) | ||
|
||
// LAUNCH SERVER | ||
fastify.listen({port: process.env.SERVER_PORT || 3000, host: process.env.SERVER_HOST || '0.0.0.0'}, (err, address) => { | ||
if (err) { | ||
console.log(err) | ||
process.exit(1) | ||
} | ||
console.info(`Server listening on ${address}`) | ||
}) | ||
return fastify | ||
} | ||
|
||
build() | ||
.then(fastify => // LAUNCH SERVER | ||
fastify.listen({ port: process.env.SERVER_PORT || 3000, host: process.env.SERVER_HOST || '0.0.0.0' }, (err, address) => { | ||
if (err) { | ||
console.log(err) | ||
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. Remove this too 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. done! |
||
process.exit(1) | ||
} | ||
console.info(`Server listening on ${address}`) | ||
})) | ||
.catch(console.log) | ||
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. Could we maybe add the error to logs 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. If t this error occurs, most likely we didn't import fastify successfully and so the logger has not been initialized |
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.
Let's remove this.
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.
done!