Nginx geo module won't use variables? - nginx

As I try to run nice Ip2Geo Importer to add geo functionality to my site, I noticed strange nginx 1.13.6 behavior. I'm in doubt if this is something intended, or I have a way out to use.
Here is the config sample:
geo $city {
ranges;
default $city_mm;
include geo/city.txt;
}
geo $city_mm {
ranges;
include geo/mm_city.txt;
}
that is, it should return content of $city_mm if value of $city can not be calculated/found, but as I run it with nginx, it returns just string $city_mm (exactly this string, not the content of the variable of that name), while $city_mm is defined at that time!
I can't see issues concerning this so just wanted to ask if I have a way to do that, maybe in different way?

So so summarize the solution from #alexander's external link, Nginx does not (currently) support dynamic defaults for geo maps, so you have to use the default feature of the regular map instead.
geo $city_geo {
ranges;
include geo/city.txt;
}
geo $city_mm {
ranges;
include geo/mm_city.txt;
}
map $city_geo $city {
"" $city_mm;
default $city_geo;
}

Related

how to add dash(-) between name of dynamic route Nextjs in url

I create a dynamic route pages/post/[postname].tsx . and when I send name to the dynamic route the url shows name with url-encode (%20,%E2,...)
I want to show name of the url with dash between words. like below url
https://stackoverflow.com/questions/68041539/using-dash-in-the-dynamic-route-name-in-nuxt-js
how can I do this?
I've used the getStaticPaths method and pass it an object of slugs before. This has worked for me when dealing with a headless CMS'.
export async function getStaticPaths() {
// Hit API to get posts as JSON
const posts = await getPosts()
// Map a new object with just the slugs
const paths = posts.map((post) => {
return { params: { slug: post.slug } }
})
// Return paths
return {
paths: paths,
fallback: true
}
}
I think I understand the problem, you're trying to use a set of strings with spaces e.g "the fundamentals of starting web development" as path param to achieve something like this https://www.geniushawlah.xyz/the-fundamentals-of-starting-web-development. That will most likely convert your spaces to %20 which is normal. I would have advised you to first use replace() method to change all spaces to hyphen before passing it as param but the replace() method only changes the first space and leave the rest. There are other ways to get rid of the spaces programmatically but may be stressful and not worth it, so I'll advise you use an hyphenated set of strings by default.
If not, try to use a for-loop with the replace() method to change all spaces to hyphens, then pass it as param.

Can I create additional axes/dimensions in Premake?

Premake 5 gives you two functions to separate independent configuration variables in your projects: configurations and platforms. So for example, you might have:
configurations { "Debug", "Release" }
platform { "Windows", "Linux" }
The documentation refers to these as axes, which is a good way to describe them, since you can have independent settings for each axis:
Really, platforms are just another set of build configuration names, providing another axis on which to configure your project.
But what if I want another axis? For example, the data types used for particular calculations:
calctypes { "Long", "Default", "Short" }
Can I create this new axis, and if so, how?
I think tags (a new feature due to be released in the next alpha build) might be what you're looking for. Here is an example from the pull request where they were implemented:
workspace 'foobar'
configurations { 'release-std', 'debug-std', 'release-blz', 'debug-blz' }
filter { 'configuration:*-std' }
tags { 'use-std' }
filter { 'configuration:*-blz' }
tags { 'use-blz' }
project 'test'
filter { 'tags:use-blz' }
includedependencies { 'blz' }
defines { 'USE_BLZ' }
filter { 'tags:use-std' }
defines { 'USE_STD' }
Update: If you would like to see how to add custom fields (e.g. defines, configurations, etc.), have a look at the api.register() calls in _premake_init.lua. To see how to enable filtering on one of these fields, have a look at this pull request.
While adding new fields is trivial and can be done anywhere, we need to do some work before it will be as simple to enable those fields for filtering.

Adding URL friendly slugs

Currently what i have is
http://www.example.com/_id
instead of displaying the generated id in the url i want to show the title of my post in the url. Such as
http://www.example.com/this_is_a_new_post
do i have to add the slug field in the collection for this? isn't there any any solution using which i can make a friendly url and i don't have to make another redundant field like slug?
P.S. I don't want to use packages. i guess it can be done without packages easily.
The simplest thing you can do is just to use /:title. Iron will automatically decode the title. Firefox handles such URLs pretty nicely. It just converts them, so the user sees the actual title including all special-chars. Also, all the iron helpers are encode the URL string correctly.
To create a slug you can use something like this function:
createURLSlug = function (url) {
var slugRegex = /[^\w\-\.\~]/g
while(slugRegex.test(url)) {
url = url.replace(slugRegex, '-')
}
return url
}
I used the wiki page on of allowed URL characters as a reference for this regex.
If you are using SimpleSchema you can also use an autoValue:
...
slug: {
type: String,
autoValue: function () {
return createURLSlug(this.field('title').value)
}
}
...

pre-populating app settings witha meteor collection

I'm trying to get my head around the way meteor work.
I'm building a site prototype and I'd like to pre-populate it with data like site.title, site.logo, site.contact.number etc...
I've created a Settings collection:
Settings = new Meteor.Collection('settings');
Settings.insert(
{
logo: 'test logo',
contact: {
human: '01 01 01 01 01',
machine: '0101010101'
}
}
)
is it possible in the html markup to then retrieve this data across templates, as Meteor is subscribed to the collection?
I'm trying to do things like:
{{settings.logo}}
<a href="{{settings.contact.machine}}" class="logo url" rel="me" {{settings.contact.human}}</a>
Meteor is running on auto publish at the moment so I'm not sure if I need to do something in my main.js file. Can Meteor access all values automatically? at the moment it prints [object,object]
update
I've created a settings.json file:
{
"public" : {
"logo" : "my fancy company name",
"contact" : {
"human" : "01 01 01 01 01 ",
"machine" : "0044101010101"
}
}
}
Then I changed my Handlebars.registerHelper to
Handlebars.registerHelper('view', function(){
return Meteor.settings.public
});
I can now access all of the settings without creating a Collection for them, much more easily.
cheers
Your approach is wrong on several levels.
The handlebar expression {{settings.contact.machine}} will insert *currentContextObject*.settings.contact.machine into the HTML, where *currentContextObject* is the template's data context.
What is your template's data context? I don't know but it doesn't matter because settings.contact.machine won't make sense either way. Settings is a collection of documents but you are trying to use it as if it were a single object.
What would work in JS is Settings.findOne().contact.machine. To access this setting across templates you would need to create a global template helper like e.g.:
if (Meteor.isClient) {
Handlebars.registerHelper("getMachineContact", function() {
return Settings.findOne().contact.machine;
});
}
Then you could use {{getMachineContact}} in your HTML.
Still this solution wouldn't be nice and you should probably be using Meteor.settings instead of a Settings collection for solving your use case.
Similar to here you could then create a global template helper that returns arbitrary values from Meteor.settings given their path, meaning you could for example write {{getSetting "contact.machine"}}. This approach would involve converting a string in dot notation ("contact.machine") into an object reference so this question might be useful.

Is there a suitable hook for intercepting all POSTs to an OpenACS/AOLServer system?

I'd like to disable all POSTs to an OpenACS/AOLServer installation. Is there an good singular place – a request-hook or wrapper/middleware – to do this?
(Bonus points if the intercept can let a few URI patterns or logged-in users through.)
Yes, this is straight forward to do. You have a choice here: you can register a proc to run instead of all POSTs, or can you register a filter to run before the POST and filter out certain users or whatever. I think the filter is a better choice.
To do this you register your proc or filter using ns_register_proc or ns_register_filter (with preauth). Put the following code in a .tcl file under the tcl folder of an OpenACS package or under the main AOLserver /web/servername/tcl directory.
Filter example:
ns_register_filter preauth POST / filter_posts
proc filter_posts {} {
set user_id [ad_verify_and_get_user_id]
set list_of_allowed_user_ids [21 567 8999]
if {[lsearch -exact $list_of_allowed_user_ids $user_id] == -1 } {
#this user isn't allowed - so redirect them
ns_returnredirect "/register/"
# tell AOLserver to abort this thread
return filter_return
} else {
# this user is allowed, tell AOLserver to continue
return filter_ok
}
}
Proc example:
ns_register_proc POST / handle_posts
proc handle_posts {} {
ns_returnredirect "http://someotherwebsite.com"
}

Resources